美好的一天,
我遇到了一些麻烦.我试图通过网络将字符数组发送到服务器.
这是我的代码:
char[] arr= {3,4};
public void sendMessage(String message){
if (out != null && !out.checkError()) {
out.print(arr);
out.flush();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时,lanshark检测到它收到了一个包含2个字节数据的数据包.好的一切都很好.
现在当我运行这个:
char[] arr= {3,160}; // notice 160 *****
public void sendMessage(String message){
if (out != null && !out.checkError()) {
out.print(arr);
out.flush();
}
}
Run Code Online (Sandbox Code Playgroud)
lanshark说数据包有3个字节的数据?确切的数据是:
03 c2 a0
现在为什么要在那里添加c2?我知道它与我的char大于127这一事实有关.但我需要发送这个160的值.
请你帮帮我.我是否需要使用其他类型的数据,或以不同的方式发送?我知道你可以在C中做到这一点.我怎么能在java中做到这一点?
这是我的out对象的代码:
PrintWriter out;
out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
Run Code Online (Sandbox Code Playgroud)
谢谢
我想知道是否有可能做到以下几点;
我想要一个与我正在开发的Android应用程序一起使用的nfc标签.
如果我刷标签并且我的应用程序安装在手机上,我想从标签中读取纯文本数据.没有什么比999更多的数字.
但是如果没有安装我的应用程序,我希望标签打开Web浏览器并重定向到可以下载它的链接?
这有可能与android已经开始阅读意图的方式有关吗?
从我对它的理解(我不是在nfc的专业人士)你只能做其中一个?
还是我错了?
编辑:
有没有办法在没有在Play商店加载应用程序的情况下这样做?这是一个大学项目,我不认为如果我公开项目,他们会很高兴.我希望将它们带到一个链接,您可以下载.apk
我有一个应用程序,它从多个套接字接收数据,然后将数据写入数据库。
我目前正在使用 EF 来执行此操作。我想知道如何才能提高效率。
我读到,批量插入速度更快,所以我只每 500 个插入保存对数据库的更改:
db.Logs_In.Add(tableItem);
if (logBufferCounter++ > 500)
{
db.SaveChanges();
logBufferCounter = 0;
}
Run Code Online (Sandbox Code Playgroud)
现在我已经分析了应用程序,74% 的工作是由该函数完成的:System.Data.Enitity.DbSet'1[System._Canon].Add
有没有更好的方法来进行插入?也许将表项排队到列表中,然后将整个列表添加到数据库上下文中。
或者也许我看错了,我应该完全避免使用 EntityFramework 来实现更高性能的插入?目前它是我的应用程序中的瓶颈,如果我查看系统资源,SQL 似乎根本没有动过眼睛。
所以我的问题:
1:如何在多次插入中实现最高效/最快的插入
2:如果EF可以接受,我该如何改进我的解决方案?
我使用的是 SQL Server 2012 企业版,传入的数据是恒定的流,但是我可以缓冲它,然后执行批量插入(如果这是更好的解决方案)。
[编辑]
进一步解释该场景。我有一个线程在并发队列上循环,该线程使该队列中的项目出列。然而,由于数据库插入是瓶颈。队列中通常有数千个条目,因此,如果还有一种异步或并行方式,我可能会利用多个线程来执行插入。
FragmentManager.findFragmentByTag("tag")我在退货时发现了一个具体的案例null。
我有一种直觉,这与时间有关?
我有一个带有以下回调的网络库:
onStart()
{
Utils.ShowLoadingDialog("loading");
}
onFinnish()
{
Utils.DismissLoadingDialog("loading");
}
Run Code Online (Sandbox Code Playgroud)
然后在我的 Utils 类中我有以下代码:
public void showLoadingDialog(String title, String message, String tag) {
DialogFragment loadingDialogFragment = new LoadingDialogFragment();
Bundle args = new Bundle();
args.putString(CommonBundleAttributes.CONNECTING_ACTIVITY_DIALOG_TITLE, title);
args.putString(CommonBundleAttributes.CONNECTING_ACTIVITY_DIALOG_MESSAGE, message);
loadingDialogFragment.setArguments(args);
FragmentTransaction transaction = fragManager.beginTransaction();
loadingDialogFragment.show(transaction, tag);
}
public void dismissLoadingDialog(String tag) {
DialogFragment dg = (DialogFragment) fragManager.findFragmentByTag(tag);
if (dg != null) {
// this reference isn't null so the dialog is available
dg.dismissAllowingStateLoss();
}
}
Run Code Online (Sandbox Code Playgroud)
现在这通常工作得很好。然而,在网络层检测到没有互联网的情况下。它会抛出一个错误,然后立即调用onFinnish(). 在这种情况下, …
我收到来自http请求的字符串,其中包含以下数据:
{"status":1,"Type":3,"Data":"<p style=\"padding-left:80px\"><\/p><ol><li><span style=\"color:#ff0000\">This<\/span><\/li><li>is a<\/li><li><strong>m<span style=\"background-color:#66cc00\">are<\/span><\/strong><\/li><\/ol><p><\/p><p style=\"padding-left:80px\"><strong style=\"text-align:left\"><span style=\"background-color:#66cc00\"><\/span><\/strong><\/p> "}
Run Code Online (Sandbox Code Playgroud)
我将其转换为JSONObject,如下所示:
jsonObj = new JSONObject(result);
Run Code Online (Sandbox Code Playgroud)
然后我需要将html作为String显示在TextView中,
我试过这个:
String data = jsonObj.getString("data");
Run Code Online (Sandbox Code Playgroud)
但数据仍为空.这适用于简单的json字符串,但我认为它可能是"角色"的原因.
我有以下按钮
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="5dp"
android:textSize="10sp"
android:text="Button" />
Run Code Online (Sandbox Code Playgroud)
现在在我的代码中,我想以编程方式根据某些因素制作动态数量的这些按钮.
现在我花了相当多的时间来尝试使用以下代码:
Button txtName = new Button(getActivity(), null, android.R.attr.buttonStyleSmall);
txtName.setClickable(false);
txtName.setTextSize(5);
txtName.setMaxLines(1);
txtName.setMaxHeight(40);
txtName.setMinHeight(0);
txtName.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
txtName.setText(tagsList.get(i));
Run Code Online (Sandbox Code Playgroud)
出于某种原因,代码不能完成我想要它做的事情.请参阅我的另一个问题:其他问题
不过我现在的问题是,我可以从上面的按钮中获取该布局代码,然后使用它来制作重复按钮,就像使用列表适配器一样吗?
换句话说,我想要一个xml描述我的按钮布局,我想让它用于同一页面上的许多按钮?
为什么这个c ++程序给我错误:
#include <iostream>
using namespace std;
int main (){
NumbersClass num;
num.setNumbers(1);
}
class NumbersClass
{
public:
NumbersClass() {}
void setNumbers(int i) { }
};
Run Code Online (Sandbox Code Playgroud)
这是我的错误:
taskbcplus.cpp(7): error C2065: 'NumbersClass' : undeclared identifier
taskbcplus.cpp(7): error C2146: syntax error : missing ';' before identifier 'num'
taskbcplus.cpp(7): error C2065: 'num' : undeclared identifier
taskbcplus.cpp(9): error C2065: 'num' : undeclared identifier
taskbcplus.cpp(9): error C2228: left of '.setNumbers' must have class/struct/union
1> type is ''unknown-type''
Run Code Online (Sandbox Code Playgroud) 我有以下操作方法:
public class MyDeviceController : ApiController
{
// GET api/<controller>
public JsonResult Get()
{
int userId = -1;
List<String> myDevices1 = new List<String>();
myDevices1.Add("1");
>> return Json(myDevices1); << Error here
}
}
Run Code Online (Sandbox Code Playgroud)
返回带有下划线红色,并显示以下错误:
cannot implicitly convert type (JsonResult to List<string>)
Run Code Online (Sandbox Code Playgroud)
我正在使用Asp.net Web Api.我认为它在使用System.web.http和System.mvc.http h之间感到困惑
我有一个名为IP的列,其中包含数据 10.001.99.108
我想运行一个脚本来改变它看起来像 10.1.99.108
我以前用过这个:
update TABLE set IP = substring(IP, patindex('%[^0]%',IP), 10)
Run Code Online (Sandbox Code Playgroud)
但这会在乞讨时删除前导零.
我不知道如何改变它来做第二段.
我String在 a 中有金额TextBox,我想除以 100。
该值应四舍五入到两位小数。我试过了,但没有得到正确的值。
这是我尝试过的:
6766/100 = 67.66
47/100 = .47
98/100 = .98
Run Code Online (Sandbox Code Playgroud)