我正在使用.php
文件使用1个唯一字段(在我的情况下为手机号码)从数据库中检索数据,并将其粘贴到我的xml
文件中,例如,我的[[数据库包含字段名称,移动设备,消息 ..,甚至我的xml
包含名称,移动设备,消息编辑框。因此,数据库中存在的数据应为我的编辑框的.setText()
。
EditText name1 = (EditText) findViewById(R.id.editText5);
string nm = json_data.getString("name"); //data at name is assigned to nm successfully
name1.setText(nm.toString()); //this line is not doing the task giving an exception(fatal exception asynctask #1)
[建议我,而不是setText应该使用什么来将值分配给我的编辑框。我尝试了ExtractedSetText
和string.getText.tostring
,进行了搜索以解决“致命异常asynctask#1”,但没有帮助。任何建议都会有很大帮助谢谢
在postExecute(line:163)::
中
Details.this.runOnUiThread(new Runnable() { public void run() { EditText name1 = (EditText) findViewById(R.id.editText5); Log.e("onPostExecute nm", nm.toString()); name1.append(nm.toString()); //but its throwing a null pointer exception //name1.setText(nm.toString()); //this is not doing the task } }
日志猫::
12-25 14:36:50.700: E/AndroidRuntime(17901): FATAL EXCEPTION: main 12-25 14:36:50.700: E/AndroidRuntime(17901): java.lang.NullPointerException 12-25 14:36:50.700: E/AndroidRuntime(17901): at com.example.pinks.Details$Fetch$1.run(Details.java:168) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.app.Activity.runOnUiThread(Activity.java:4766) 12-25 14:36:50.700: E/AndroidRuntime(17901): at com.example.pinks.Details$Fetch.onPostExecute(Details.java:163) 12-25 14:36:50.700: E/AndroidRuntime(17901): at com.example.pinks.Details$Fetch.onPostExecute(Details.java:1) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.os.AsyncTask.finish(AsyncTask.java:631) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.os.AsyncTask.access$600(AsyncTask.java:177) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.os.Handler.dispatchMessage(Handler.java:99) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.os.Looper.loop(Looper.java:174) 12-25 14:36:50.700: E/AndroidRuntime(17901): at android.app.ActivityThread.main(ActivityThread.java:4952) 12-25 14:36:50.700: E/AndroidRuntime(17901): at java.lang.reflect.Method.invokeNative(Native Method) 12-25 14:36:50.700: E/AndroidRuntime(17901): at java.lang.reflect.Method.invoke(Method.java:511) 12-25 14:36:50.700: E/AndroidRuntime(17901): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027) 12-25 14:36:50.700: E/AndroidRuntime(17901): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794) 12-25 14:36:50.700: E/AndroidRuntime(17901): at dalvik.system.NativeStart.main(Native Method)