gpt4 book ai didi

java.lang.RuntimeException :An error occured while executing doInBackground() 错误

转载 作者:行者123 更新时间:2023-11-30 02:51:31 24 4
gpt4 key购买 nike

我看过其他相关帖子,我知道错误出在 doInBackground 方法中,而且理解错误的发生,但我不明白我必须更改代码的哪个位置或传达 onPostExecute 方法。如果有人有一些知道这是什么,我应该更改为代码,谢谢。以下是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);
}
});

}

}

下面是错误

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 在第 141 行为 null。您遇到解析器错误,这意味着解析器无法读取您的对象,在这种情况下,它返回 null。

下一行,您尝试使用 json 对象 (json.toString()) 并获得一个 NullPointerException

查看您尝试在线解析的对象:

JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);

该行返回一个空对象。

关于java.lang.RuntimeException :An error occured while executing doInBackground() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24070631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com