我有一个应用程序,它显示一个带有列表视图的对话框。在用户从listview中选择一个选项后,我将使用用户选择的信息更改记录。为此,我考虑使用命令setResult(RESULT\u OK,intent) 但我的代码正在生成以下异常:
09-25 12:01:06.035: E/AndroidRuntime(8783): FATAL EXCEPTION: main
09-25 12:01:06.035: E/AndroidRuntime(8783): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { flg=0x20000000 cmp=com.sisteplantbrasil/.WorkOrderInfo (has extras) }} to activity {com.sisteplantbrasil/com.sisteplantbrasil.WorkOrderInfo}: android.os.NetworkOnMainThreadException
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.ActivityThread.deliverResults(ActivityThread.java:3182)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.os.Handler.dispatchMessage(Handler.java:99)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.os.Looper.loop(Looper.java:137)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.ActivityThread.main(ActivityThread.java:4898)
09-25 12:01:06.035: E/AndroidRuntime(8783): at java.lang.reflect.Method.invokeNative(Native Method)
09-25 12:01:06.035: E/AndroidRuntime(8783): at java.lang.reflect.Method.invoke(Method.java:511)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
09-25 12:01:06.035: E/AndroidRuntime(8783): at dalvik.system.NativeStart.main(Native Method)
09-25 12:01:06.035: E/AndroidRuntime(8783): Caused by: android.os.NetworkOnMainThreadException
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.io.IoBridge.connectErrno(IoBridge.java:144)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.io.IoBridge.connect(IoBridge.java:112)
09-25 12:01:06.035: E/AndroidRuntime(8783): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
09-25 12:01:06.035: E/AndroidRuntime(8783): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
09-25 12:01:06.035: E/AndroidRuntime(8783): at java.net.Socket.connect(Socket.java:842)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
09-25 12:01:06.035: E/AndroidRuntime(8783): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
09-25 12:01:06.035: E/AndroidRuntime(8783): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
09-25 12:01:06.035: E/AndroidRuntime(8783): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
09-25 12:01:06.035: E/AndroidRuntime(8783): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.sisteplantbrasil.webservices.PrismaWebServices.getDateTimeNow(PrismaWebServices.java:144)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.sisteplantbrasil.entities.LaborRecord.getCurrentDate(LaborRecord.java:120)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.sisteplantbrasil.entities.LaborRecord.getLaborEndDate(LaborRecord.java:146)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.sisteplantbrasil.queries.sql.LaborRecordDBQueries.insertLaborRecord(LaborRecordDBQueries.java:35)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.sisteplantbrasil.entities.LaborRecord.offlineSave(LaborRecord.java:167)
09-25 12:01:06.035: E/AndroidRuntime(8783): at com.sisteplantbrasil.WorkOrderInfo.onActivityResult(WorkOrderInfo.java:492)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
09-25 12:01:06.035: E/AndroidRuntime(8783): at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
09-25 12:01:06.035: E/AndroidRuntime(8783): ... 11 more
我的代码:
public void onClickEndLabor(View v) {
if (selectedNextWorkOrderState != null) {
Intent intent;
if (showNotes) {
EditText txtNotes = (EditText) findViewById(R.id.txtNotes);
intent = IntentFactory.createWorkOrderInfo(
WorkOrderStateWorkflow.this,
selectedNextWorkOrderState, txtNotes.getText()
.toString(), Intent.FLAG_ACTIVITY_SINGLE_TOP);
} else {
intent = IntentFactory.createWorkOrderInfo(
WorkOrderStateWorkflow.this,
selectedNextWorkOrderState, "",
Intent.FLAG_ACTIVITY_SINGLE_TOP);
}
setResult(RESULT_OK, intent);
finish();
}
}
WorkOrderInfo活动:
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
if (resultCode == RESULT_OK) {
super.onActivityResult(requestCode, resultCode, intent);
Bundle extras = intent.getExtras();
if (extras != null) {
WorkOrderState nextWOState = (WorkOrderState) extras
.getSerializable("workOrderState");
nextState = nextWOState.getWorkOrderState();
String notes = extras.getString("notes");
WorkOrder workOrder = Application.getInstance().getWorkOrder();
previousWOState = new WorkOrderState(
workOrder.getWorkOrderState(),
workOrder.getWorkOrderStateName());
if (Application.getInstance().useLaborRecord()) {
lre.setWorkOrder(workOrder);
lre.setNotes(notes);
progress = ProgressDialog.show(this, getResources()
.getString(R.string.Wait), getResources()
.getString(R.string.EndingLabor));
if (Application.getInstance().getStatus() == AppStatus.ONLINE) {
lre.asyncSave(endHandler);
lre.getWorkOrder().offlineSave(false);
lre.offlineSave(false, false);
} else {
if (lre.offlineSave(true, false)
&& lre.getWorkOrder().offlineSave(false)) {
endHandler.sendEmptyMessage(0);
} else {
Message msg = new Message();
msg.obj = new QueryException(getResources()
.getString(R.string.ErrorSaving));
endHandler.sendMessage(msg);
}
}
} else {
ChangeWOState changeState = new ChangeWOState(
WorkOrderInfo.this);
changeState.execute();
}
}
}
}
有人能告诉我代码出了什么问题吗?谢谢你的关注!!!
NetworkOnMainThreadException:当应用程序尝试在其主线程上执行网络操作时引发的异常。
http://android-developers.blogspot.in/2009/05/painless-threading.html
这是一个链接,说明如何使用异步任务
http://developer.android.com/reference/android/os/AsyncTask.html
android.os.NetworkOnMainThreadException与android 4.2
http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html
http://blog.vogella.com/2012/02/22/android-strictmode-networkonmainthreadexception/
我正在使用Geospark1.3.1,在那里我试图找到包含在多边形中的所有geo点。我使用sql命令:
我很好奇是否可以在以下情况下使用orElseThrow(),或者是否有更Java的8种方法可以将其等效为1行?
AFAIK将/提交到是我想并行执行资源密集型代码的方法。因此,我的方法结构: 我在上面的代码中标记了两个可能发生故障的点。对于这两种情况,可用于错误处理的选项非常不同。 在提交任务之前,可能会出现一些问题,例如参数无效,一些可能失败的快速预处理代码。 我在这里看到了几种表示失败的方式: 如果提供给的无效立即返回null。在这种情况下,我必须检查每次调用时是否返回null。 抛出检查过的异常而不是上
我们正在使用我们的GraphQL后端WebTestClient(SpringBoot)进行测试,但很难确定测试失败的原因。我们的代码如下所示: 我得到的是带有以下消息的stacktrace: Java语言lang.AssertionError:JSON路径“$.data.movie.id”处没有值 ... 原因:com.jayway.jsonpath.PathNotFoundException:路
请帮我解决这个Android相机。 我得到的错误如下: 它也给出了这个警告,这是奇怪的,因为我压缩图像: 我的应用程序允许用户从图库中选择一张照片或使用相机拍摄一张照片。正如你从代码中可以看出的那样,用户添加的照片数量没有限制。 在主页(createPropertyActivity*5*)中,用户点击拍照按钮,选择相机或画廊,然后选择(或拍摄)一张照片,然后应用程序进入一个页面(createPro
我是一个很新的反应原生应用程序开发人员。请帮助我解决以下问题,我在执行react-native Run-Android时遇到以下问题。 运行jetifier将库迁移到AndroidX的信息。您可以使用“--no-jetifier”标志禁用它。Jetifier找到1112个文件要转发JEtify。使用8名工作人员...信息正在启动JS服务器...“adb”不能识别为内部或外部命令、可操作程序或批处理