0

Hi I'm trying to develop an app that could list all installed app's along with their cache, and I'm doing it, but problem is when ever I tap on list I get Force Close

Here is my code

new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() 
{
    pd = ProgressDialog.show(Messages.this, "Loading..","Please Wait", true, false);
}// End of onPreExecute method

@Override
protected Void doInBackground(Void... params) 
{
    MessageDetails Detail;
    Detail = new MessageDetails();
    Detail.setIcon(getPackageManager().getApplicationIcon( pStats.packageName ));
    Detail.setName(title);
    Detail.setSub("Cache Size -> "+(((pStats.cacheSize/1024) > 0)?(pStats.cacheSize/1024):"No Cache"));
    details.add(Detail);
    return null;
}// End of doInBackground method

@Override
protected void onPostExecute(Void result) {
    msgList.setAdapter(new CustomAdapter(details, Messages.this));
    pd.dismiss();
}// End of onPostExecute method
 }.execute((Void[]) null);

Please help me to solve this riddle, Thanks in advance.

Stack Trace

E/AndroidRuntime(1143): java.lang.IllegalStateException: The content of the adapter has 
changed but ListView did not receive a notification. 
Make sure the content of your adapter is not modified from a background thread, 
but only from the UI thread. 
[in ListView(2131230725, class android.widget.ListView) 
with Adapter(class com.example.temptocache.CustomAdapter)]
Chethan Shetty
  • 1,972
  • 4
  • 25
  • 45
  • Your problem is not in the list, it is in the code that handles the list view tap. Show that code. – Femi Jul 10 '13 at 06:42
  • I'm not handling any `tap event` @Femi I don't want any thing to happen when we tap on list. – Chethan Shetty Jul 10 '13 at 06:45
  • @ChethanShetty stack trace pls – Raghunandan Jul 10 '13 at 06:46
  • I didn't say you wanted anything to happen. You said **but problem is when ever I tap on list I get Force Close**: that means there's some code in your activity that is responding when you tap. You should show the entire activity code, which will include the tap handler (the `onListItemClick` function). – Femi Jul 10 '13 at 06:49
  • @Femi I didn't implemented `onListItemClick` intentionally to avoid `onClick` events – Chethan Shetty Jul 10 '13 at 06:52
  • @ChethanShetty Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Your updating adapter from background thread. details is a list? – Raghunandan Jul 10 '13 at 06:55
  • @Raghunandan Yes thats my requirement because I want to load lot's of data, so I'm using background thread, is there a way to solve this problem – Chethan Shetty Jul 10 '13 at 06:56
  • use `runOnUiThread` if need to update ui from doInbackground – Raghunandan Jul 10 '13 at 06:57
  • @Raghunandan that's really good idea, I'm really trying to use the `runOnUiThread` in my code, but don't know where and how, can you please help me if you don't mind – Chethan Shetty Jul 10 '13 at 07:00
  • http://stackoverflow.com/questions/9296539/android-runonuithread-vs-asynctask. search on so lots of similar posts – Raghunandan Jul 10 '13 at 07:02
  • http://stackoverflow.com/questions/17566106/how-do-i-put-asynctask-code-to-thread-handler Please go to this link @Raghunandan – Chethan Shetty Jul 10 '13 at 08:45
  • @Femi go to this link http://stackoverflow.com/questions/17566106/how-do-i-put-asynctask-code-to-thread-handler – Chethan Shetty Jul 10 '13 at 08:46

0 Answers0