I understand the meaning of this error. I found many similar questions here at stackoverflow.com and I have tried to implement the answers those were suggested but still I am getting this error. What I am trying to do is using php web service I am extracting the data from mysql database server and trying to display it in listview using AsyncTask as follows:
class LoadAllProducts extends AsyncTask<String, String, ArrayList<HashMap<String, String>>>
{
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
protected ArrayList<HashMap<String, String>> doInBackground(String... args)
{
List<NameValuePair> params = new ArrayList<NameValuePair>();
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
Log.d("All Products: ", json.toString());
try {
JSONArray files = json.getJSONArray(TAG_FILES);
for(int i=0;i<files.length();i++)
{
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = files.getJSONObject(i);
String file_name = e.getString(TAG_FILE_NAME);
String sender = e.getString(TAG_SENDER);
String subject = e.getString(TAG_SUBJECT);
map.put(TAG_SENDER, sender);
map.put(TAG_SUBJECT, subject);
mylist.add(map);
}
} catch (JSONException e)
{
e.printStackTrace();
Log.e("log_tag", "Error parsing data "+e.toString());
}
return mylist;
}
This was suggested in many answers that all the processing should be done in doInBackground function. Now below is the code to display this arraylist in ListView
protected void onPostExecute(String file_url)
{
pDialog.dismiss();
runOnUiThread(new Runnable()
{
public void run()
{
String[] from = { TAG_SENDER, TAG_SUBJECT };
int[] to = { android.R.id.text1, android.R.id.text2 };
ListAdapter adapter = new SimpleAdapter(AllProductsActivity.this, mylist,
android.R.layout.simple_list_item_2, from , to);
setListAdapter(adapter);
}
});
}
Please Help cause first of all I am a beginner of android and I dont have any clue how to solve this problem . Please check my code and let me know the problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…