public ProgressDialog pDialognew;static JsONParser jParser = new JsONParser();ArrayList<HashMap<String,String>> allValueList;class SearchData extends AsyncTask<String,String,String> { @OverrIDe protected voID onPreExecute() { super.onPreExecute(); pDialognew = new ProgressDialog(Activity.this); pDialognew.setMessage("Loading. Please wait..."); pDialognew.setIndeterminate(false); pDialognew.setCancelable(true); pDialognew.show();}@OverrIDeprotected String doInBackground(String... params) { runOnUiThread(new Runnable() { @OverrIDe public voID run() { int success;try { List<nameValuePair> params = new ArrayList<nameValuePair>(); params.add(new BasicnameValuePair("match",pname)); JsONObject Json = jParser.makehttpRequest(GlobalServerLocation.url_pol,"GET",params); success = Json.getInt("success"); if (success == 1) { JsONArray productObj = Json.getJsONArray("object"); // JsON Array Log.i("val",productObj.toString()); // Correct JsON total = productObj.length(); // Correct number of rows Log.i("Len",String.valueOf(total)); for (int j = 0; j < productObj.length(); j++) { JsONObject productnew = productObj.getJsONObject(j); String LS = productnew.getString(TAG_LS); String CN = productnew.getString(TAG_CN); String SN = productnew.getString(TAG_SN); String PN = productnew.getString(TAG_PN); HashMap<String,String> map = new HashMap<String,String>(); map.put(TAG_LS,LS); map.put(TAG_CN,CN); map.put(TAG_SN,SN); map.put(TAG_PN,PN); allValueList.add(map); } } else { Log.i("Error"," Some Error from PHP Script"); }}catch (JsONException e) { Log.i("Error",e.toString()); }} }); return null;}@OverrIDeprotected voID onPostExecute(String file_url) { pDialognew.dismiss(); // line 113 }}
08-23 17:17:33.449: E/AndroIDRuntime(31930): FATAL EXCEPTION: main08-23 17:17:33.449: E/AndroIDRuntime(31930): java.lang.NullPointerException08-23 17:17:33.449: E/AndroIDRuntime(31930): at my.india.our.app$SearchData.run(app.java:113)08-23 17:17:33.449: E/AndroIDRuntime(31930): at androID.os.Handler.handleCallback(Handler.java:587)08-23 17:17:33.449: E/AndroIDRuntime(31930): at androID.os.Handler.dispatchMessage(Handler.java:92)08-23 17:17:33.449: E/AndroIDRuntime(31930): at androID.os.Looper.loop(Looper.java:123)08-23 17:17:33.449: E/AndroIDRuntime(31930): at androID.app.ActivityThread.main(ActivityThread.java:3729)08-23 17:17:33.449: E/AndroIDRuntime(31930): at java.lang.reflect.Method.invokeNative(Native Method)08-23 17:17:33.449: E/AndroIDRuntime(31930): at java.lang.reflect.Method.invoke(Method.java:507)08-23 17:17:33.449: E/AndroIDRuntime(31930): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)08-23 17:17:33.449: E/AndroIDRuntime(31930): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:632)08-23 17:17:33.449: E/AndroIDRuntime(31930): at dalvik.system.NativeStart.main(Native Method)
如果需要Code的任何其他部分,请告诉我.
解决方法 通常AsyncTask用作新线程来执行繁重的 *** 作而不会阻塞主UI线程.但是,您已经使用了我在AsyncTask的doInBackground()中提到的代码,这将再次使进程在主线程中执行(特别是在更高版本的手机),阻止它.所以,最好删除以下行并尝试运行它..runOnUiThread(new Runnable() { @OverrIDe public voID run() {}};总结
以上是内存溢出为你收集整理的android – 异步任务中的空指针错误全部内容,希望文章能够帮你解决android – 异步任务中的空指针错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)