Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:02:47+00:00 2026-05-27T06:02:47+00:00

I getting the exception as * java.lang.IllegalStateException: The content of the adapter has changed

  • 0

I getting the exception as
“*java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the cont*ent of your adapter is not modified from a background thread, but only from the UI thread.“

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

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

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…

public class SearchProperty extends Activity
{

boolean isDone;
List<Property> properties = new ArrayList<Property>();
ListView list;
ArrayAdapter<Property> 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<Property>(this,
            android.R.layout.simple_list_item_1, properties);
    list.setAdapter(adapter);

    list.setOnItemClickListener( new OnItemClickListener() 
    {

        public void onItemClick(AdapterView<?> 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<String, Void, String> {
    @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();
        }

    }

}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:02:48+00:00Added an answer on May 27, 2026 at 6:02 am

    Taking some snippet of the code from above:

    List<Property> properties = new ArrayList<Property>();
    

    Then you have

    adapter = new ArrayAdapter<Property>(this,
            android.R.layout.simple_list_item_1, properties);
    list.setAdapter(adapter);
    

    The way you described your code, looks like you are adding to properties in from the FileParserTask (even though I cant see that in your code above). If i am right and you are adding to properties in FileParserTask then it could be likely that you ll get this error. Reason being, your underline properties is modified in a NON-UI Thread which means your ArrayAdapter is also modified in NON-UI thread.

    This leads to inconsistent state and you get the above exception. Try to move your parser code to AsyncTask with slight design change.

    One option is load all properties in a separate list and then create and set new adapter on ListView in onPostExecute. This will work if you dont want to see updated ListView while the content is being added but you still want to see the progress status.

    Second option is, create a temp list to store few properties as you parse. When the list is reached a certain limit (say 5) then publishProgress and in onProgressUpdate you can add this to the other List which is attached to the adapter. NOTE: You have try this one to see how it behaves.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting this exception: Exception: java.lang.IllegalStateException: Can't copy a recycled bitmap My code is:
I m getting exception as follow. Can anybody help me? 06-16 11:32:48.237: ERROR/AndroidRuntime(9223): java.lang.IllegalStateException:
i'm getting exception on Transformer transformer = tFactory.newTransformer(StreamXSL); but the error below is not
I am getting an exception saying : java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required When
I am getting following exception: java.lang.UnsupportedClassVersionError: net/sourceforge/barbecue/BarcodeException : **Unsupported major.minor version 0.0** at java.lang.ClassLoader.defineClass1(Native
I am getting an exception: java.lang.IllegalArgumentException: cannot add to layout: constraints must be a
I have downloaded java.sizeOf , but I am getting this exception. I am running
I am getting following error message: java.lang.IllegalStateException: Neither BindingResult nor plain target object for
I'm new to using Hibernate with Java. I'm getting the following exception. The stuff
I'm getting an exception from Cruise Control about not being able to connect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.