Listview and adapted are throwing "java.lang.IllegalStateException: "
<p>I getting the exception as
"<strong>*<em>java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the cont</em>*ent of your adapter is not modified from a background thread, but only from the UI thread.</strong>"</p>

<p>My Code has Two threads one is for SAX parsing and another is thread extending asynctask class</p>

<p>which is checking the contents every time ArrayList contents are changed.. And calling adapter.notifyDatasetChange() method in onProgressUpdate()..</p>

<p>But I want the output as the parser progresses the parsing, the respected element should be
added to the listview.... Please help me guyzzz.....
I have the  code as...</p>

<p>public class SearchProperty extends Activity 
{</p>

<pre><code>boolean isDone;
List&lt;Property&gt; properties = new ArrayList&lt;Property&gt;();
ListView list;
ArrayAdapter&lt;Property&gt; adapter;
InputStream in;
ProgressDialog dialog;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.newlay);

    list = (ListView) findViewById(R.id.mylistview);
    list.setPadding(0, 20, 0, 20);
    dialog = new ProgressDialog(this);
    dialog.setCancelable(true);
    dialog.setMessage("Please Wait...");
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    adapter = new ArrayAdapter&lt;Property&gt;(this,
            android.R.layout.simple_list_item_1, properties);
    list.setAdapter(adapter);

    list.setOnItemClickListener( new OnItemClickListener() 
    {

        public void onItemClick(AdapterView&lt;?&gt; parent, View view, int pos,
                long id) {
            Toast.makeText( SearchProperty.this , "Please Wait... Application is under progress..." , Toast.LENGTH_SHORT).show();
        }


    });

    FileParserTask task = new FileParserTask();

    Thread thread = new Thread(task);
    thread.start();

    SetTimeoutTask task11 = new SetTimeoutTask();
    task11.execute();



    System.out.println("I m done!!");
}

**// This thread is checking arraylist time to time after 50 ms and call on progressUpdate**
private class SetTimeoutTask extends AsyncTask&lt;String, Void, String&gt; {
    @Override

    protected void onPreExecute() { 

        dialog.show();

    };
    protected String doInBackground(String... urls) 
    {
    //  Log.e("...","in do InBackground.....");
        try {
            for (;;) {
                if (isDone)
                    break;
                publishProgress();
                Thread.sleep(50);

            }
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        dialog.dismiss();


    }
    @Override
    protected void onProgressUpdate(Void... values) 
    {

        //Log.e("...","in onprogressupdate.....");
        super.onProgressUpdate(values);
        if(list.getAdapter()!=null)
        adapter.notifyDataSetChanged();
    }

}


    **// this thread is doing parsing of xml file in background....**

class FileParserTask implements Runnable {

    @Override
    public void run() {


        try {
            in = getAssets().open("property.xml");
            PropertyHandler myhandler = new PropertyHandler(properties);
            XMLReader xmlReader = SAXParserFactory.newInstance()
                    .newSAXParser().getXMLReader();
            xmlReader.setContentHandler(myhandler);
            xmlReader.parse(new InputSource(in));
            isDone = true;
            System.out.println("Done!!!");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // EstateParser.parse(in,properties,adapter);
        catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParserConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FactoryConfigurationError e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
</code></pre>

<p>}</p>
