[英]java.lang.RuntimeException:An error occured while executing doInBackground()
I have seen and other relevant posts and I understand that the error is in doInBackground method moreover understands and from mistakes occurring, but I can't understand which place of code I must change or to convey onPostExecute method.If someone has some idea what's this I should change to code, thanks. 我已经看过其他相关的文章,并且我知道该错误在doInBackground方法中还可以理解并从发生的错误中了解,但是我不明白我必须更改代码的位置或传达onPostExecute方法。如果有人知道这是什么,我应该更改代码,谢谢。 The following is the code of doInBackground method etc.
以下是doInBackground方法等的代码。
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON response
Log.d("All products:",json.toString()); //141 line
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_CLASSES);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_PID);
String name = c.getString(TAG_NAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PID, id);
map.put(TAG_NAME, name);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),NewProductActivity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(
AllProductsActivity.this, productsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME},
new int[] { R.id.id, R.id.name });
// updating listview
setListAdapter(adapter);
}
});
}
}
And the following is the ERRORS 而以下是错误
06-05 20:06:49.454: E/Buffer Error(1981): Error converting result java.lang.NullPointerException: lock == null
06-05 20:06:49.509: E/JSON Parser(1981): Error parsing data org.json.JSONException: End of input at character 0 of
06-05 20:06:49.584: W/dalvikvm(1981): threadid=10: thread exiting with uncaught exception (group=0xb4da3908)
06-05 20:06:49.664: E/AndroidRuntime(1981): FATAL EXCEPTION: AsyncTask #1
06-05 20:06:49.664: E/AndroidRuntime(1981): java.lang.RuntimeException: An error occurred while executing doInBackground()
06-05 20:06:49.664: E/AndroidRuntime(1981): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-05 20:06:49.664: E/AndroidRuntime(1981): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-05 20:06:49.664: E/AndroidRuntime(1981): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-05 20:06:49.664: E/AndroidRuntime(1981): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-05 20:06:49.664: E/AndroidRuntime(1981): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-05 20:06:49.664: E/AndroidRuntime(1981): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-05 20:06:49.664: E/AndroidRuntime(1981): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-05 20:06:49.664: E/AndroidRuntime(1981): at jav a.lang.Thread.run(Thread.java:856)
06-05 20:06:49.664: E/AndroidRuntime(1981): Caused by: java.lang.NullPointerException
06-05 20:06:49.664: E/AndroidRuntime(1981): at com.panos.appphpconnect.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:141)
06-05 20:06:49.664: E/AndroidRuntime(1981): at com.panos.appphpconnect.AllProductsActivity$LoadAllProducts.doInBackground(AllProductsActivity.java:1)
06-05 20:06:49.664: E/AndroidRuntime(1981): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-05 20:06:49.664: E/AndroidRuntime(1981): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-05 20:06:49.664: E/AndroidRuntime(1981): ... 4 more
06-05 20:07:03.554: W/Trace(1981): Unexpected value from nativeGetEnabledTags: 0
Objet json
is null in line 141. You have a parser error, that means that the parser can't read your object and in this case, it returns null. Objet
json
在第141行中为null。您遇到解析器错误,这意味着解析器无法读取您的对象,在这种情况下,它返回null。
Next line, you try to use the json object ( json.toString()
) and you obtain a NullPointerException
. 下一行,您尝试使用json对象(
json.toString()
),并获得NullPointerException
。
Have a look at the object you try to parse on line: 看一下您尝试在线解析的对象:
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
That line returns a null object. 该行返回一个空对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.