Java.lang.IllegalStateException:Observer Adapterdatasetobserver is not register setadapter null pointer

Source: Internet
Author: User

If you and I describe the following several things, then this I check out the bug solution may be able to solve your problem

1.setadapter on the onclick event
2. The adapter is written as standard after the optimization
3. The data is sometimes empty, sometimes can be adapted, as long as the time is empty, and then the data will not be able to fit

Workaround:

Idea: In the adapter to determine whether the data is empty, if it is empty on the new array to give it a value,
If not null, it is equal to the value passed in.

Procedure: Start by giving adapter the data source null, write a UpdateData method yourself
Direct update after click, Setadapter is null
Specific operation code:

**adapter Construction Method * * Public Governmentinstitutionadapter(Context Mcontext, list<governmentinstitutionbean> institutionbeanslist) { This. Mcontext = Mcontext;//Determine if it is empty        if(Institutionbeanslist = =NULL) {institutionbeanslist =NewArraylist<governmentinstitutionbean> (); }Else{ This. institutionbeanslist = institutionbeanslist; }    }//Write your own UpdateData method     Public void Updateadapter(list<governmentinstitutionbean> institutionbeanslist) {if(Institutionbeanslist = =NULL) This. institutionbeanslist =NewArraylist<governmentinstitutionbean> ();Else             This. institutionbeanslist = institutionbeanslist; This. notifydatasetchanged (); }

Specific steps in the activity:

SearchButton.Setonclicklistener (NewOnclicklistener () {//1.adapter Initialization, note that the data is nullGovernmentinstitutionadapter Adapter= NewGovernmentinstitutionadapter (Getapplicationcontext (),NULL); @Override Public voidOnClick (View v) {.......    ....    //2. Calling the Updateadapter method is equivalent to fitting aAdapter.Updateadapter (Dynamic Data source to be adapted);...    //3. Last SetadapterListview.Setadapter (adapter);}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java.lang.IllegalStateException:Observer Adapterdatasetobserver is not register setadapter null pointer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.