我试图在片段中使用AsyncTask任务,但我无法获得价值。我在Activity中使用它没有问题。但我无法做到碎片。我怎么解决这个问题。对不起我的工作。
这是我的错误:
03-25 11:19:19.659: E/AndroidRuntime(28730): FATAL EXCEPTION: AsyncTask #2
03-25 11:19:19.659: E/AndroidRuntime(28730): Process: com.isosoft.vale, PID: 28730
03-25 11:19:19.659: E/AndroidRuntime(28730): java.lang.RuntimeException: An error occured while executing doInBackground()
03-25 11:19:19.659: E/AndroidRuntime(28730): at android.os.AsyncTask$3.done(AsyncTask.java:300)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
03-25 11:19:19.659: E/AndroidRuntime(28730): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.lang.Thread.run(Thread.java:841)
03-25 11:19:19.659: E/AndroidRuntime(28730): Caused by: java.lang.NullPointerException
03-25 11:19:19.659: E/AndroidRuntime(28730): at com.isosoft.vale.Kayit$AsyncCallWS.doInBackground(Kayit.java:401)
03-25 11:19:19.659: E/AndroidRuntime(28730): at com.isosoft.vale.Kayit$AsyncCallWS.doInBackground(Kayit.java:1)
03-25 11:19:19.659: E/AndroidRuntime(28730): at android.os.AsyncTask$2.call(AsyncTask.java:288)
03-25 11:19:19.659: E/AndroidRuntime(28730): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
03-25 11:19:19.659: E/AndroidRuntime(28730): ... 4 more
答案 0 :(得分:0)
我猜你的崩溃是NullPointerException,
这是你有问题的一行 -
private ProgressDialog dialog = new ProgressDialog(getActivity());
您可能会从null
获得getActivity()
。从哪个州/方法执行asynctask obj?
在您的asynctask中使用全局
String URL = "http://" + global.getDBHosturl() + "/myvale/valeservis.asmx";
但正如我所见,您的全局初始化为
GlobalClass global = (GlobalClass) getApplicationContext();
你也有 -
private GlobalClass getApplicationContext() {
// TODO Auto-generated method stub
return null;
}
所以基本上你的全局是null
因此你得到了NPE。希望这可以帮助。
似乎你试图通过错误覆盖这两种方法 -
private GlobalClass getApplicationContext() {
// TODO Auto-generated method stub
return null;
}
private com.isosoft.vale.CustomAutoCompleteTextView findViewById(
int txtModel) {
// TODO Auto-generated method stub
return null;
}
我相信你应该删除它们。