Egg-sore Android Baseadapter

Source: Internet
Author: User

1  Packagecom.moniter.helperclasses;2 3 Importjava.util.List;4 5 ImportAndroid.content.Context;6 ImportAndroid.view.LayoutInflater;7 ImportAndroid.view.View;8 ImportAndroid.view.ViewGroup;9 ImportAndroid.widget.BaseAdapter;Ten ImportAndroid.widget.ImageView; One ImportAndroid.widget.TextView; A  - ImportCOM.HANVON.MONITER.R; -  the  Public classSitelistadapterextendsBaseadapter { -  -     //List of places -     Privatelist<siteinformation> sites =NULL; +     PrivateLayoutinflater Minflater; -  +     //Constructor A      PublicSitelistadapter (context context, list<siteinformation>sites) { at          This. Sites =sites; -          This. Minflater =Layoutinflater.from (context); -     } -  -     //returns the number of list items - @Override in      Public intGetCount () { -         returnsites.size (); to     } +  - @Override the      PublicObject GetItem (intposition) { *         returnSites.get (position); $     }Panax Notoginseng  - @Override the      Public LongGetitemid (intposition) { +         returnposition; A     } the  +@SuppressWarnings ("null") - @Override $      PublicView GetView (intposition, View Convertview, ViewGroup parent) { $         //get location position corresponding site information -Siteinformation Siteinfo =Sites.get (position); -  the         //get the layout file for the ListView -Convertview = Minflater.inflate (R.layout.site_list_item,NULL);Wuyi          the         //Initialize Viewholder -Viewholder Viewholder =NULL; Wu          -         //Bindings for View About         if(Convertview = =NULL) { $Viewholder =NewViewholder (); -Viewholder.site_name =(TextView) Convertview - . Findviewbyid (r.id.name_site); -Viewholder.value_noise =(TextView) Convertview A . Findviewbyid (r.id.noise); +Viewholder.value_dust =(TextView) Convertview the . Findviewbyid (r.id.dust); -Viewholder.status_noise =(ImageView) Convertview $ . Findviewbyid (r.id.color_indicator_noise); theViewholder.status_dust =(ImageView) Convertview the . Findviewbyid (r.id.color_indicator_dust); the              the Convertview.settag (viewholder); -}Else { inViewholder =(Viewholder) Convertview.gettag (); the         } the  About         //get the corresponding value: hold the wrong!!!!! Why????  theViewHolder.site_name.setText ("123");//??? Siteinfo.getsitename () the ViewHolder.value_noise.setText (Siteinfo.getnoisevalue ()); the ViewHolder.value_dust.setText (Siteinfo.getdustvalue ()); + ViewHolder.status_noise.setBackgroundResource (Siteinfo.getnoisestatus ()); - ViewHolder.status_dust.setBackgroundResource (Siteinfo.getduststatus ()); the         Bayi         //returns the poistion corresponding view the         returnConvertview; the     } -      -     Static classViewholder { the          PublicTextView site_name; the          PublicTextView value_noise; the          PublicTextView Value_dust; the          PublicImageView status_noise; -          PublicImageView Status_dust; the     } the}

Always error in line 75th. Did not find the reason for a day.

06-16 18:09:50.232:e/androidruntime (10487): FATAL exception:main
06-16 18:09:50.232:e/androidruntime (10487): java.lang.NullPointerException
06-16 18:09:50.232:e/androidruntime (10487): at Com.moniter.helperclasses.SiteListAdapter.getView ( SITELISTADAPTER.JAVA:75)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.AbsListView.obtainView (abslistview.java:2040)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.ListView.makeAndAddView (listview.java:1772)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.ListView.fillDown (listview.java:672)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.ListView.fillFromTop (listview.java:732)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.ListView.layoutChildren (listview.java:1625)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.AbsListView.onLayout (abslistview.java:1870)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.setChildFrame (linearlayout.java:1652)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.layoutVertical (linearlayout.java:1510)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.onLayout (linearlayout.java:1415)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.setChildFrame (linearlayout.java:1652)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.layoutVertical (linearlayout.java:1510)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.onLayout (linearlayout.java:1415)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.setChildFrame (linearlayout.java:1652)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.layoutVertical (linearlayout.java:1510)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.onLayout (linearlayout.java:1415)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.RelativeLayout.onLayout (relativelayout.java:930)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.FrameLayout.onLayout (framelayout.java:443)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.setChildFrame (linearlayout.java:1652)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.layoutVertical (linearlayout.java:1510)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.LinearLayout.onLayout (linearlayout.java:1415)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.widget.FrameLayout.onLayout (framelayout.java:443)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.View.layout (view.java:11418)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewGroup.layout (viewgroup.java:4328)
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewRootImpl.performTraversals (viewrootimpl.java:1489 )
06-16 18:09:50.232:e/androidruntime (10487): at Android.view.ViewRootImpl.handleMessage (viewrootimpl.java:2442)
06-16 18:09:50.232:e/androidruntime (10487): at Android.os.Handler.dispatchMessage (handler.java:99)
06-16 18:09:50.232:e/androidruntime (10487): at Android.os.Looper.loop (looper.java:137)
06-16 18:09:50.232:e/androidruntime (10487): at Android.app.ActivityThread.main (activitythread.java:4441)
06-16 18:09:50.232:e/androidruntime (10487): at Java.lang.reflect.Method.invokeNative (Native Method)
06-16 18:09:50.232:e/androidruntime (10487): at Java.lang.reflect.Method.invoke (method.java:511)
06-16 18:09:50.232:e/androidruntime (10487): at Com.android.internal.os.zygoteinit$methodandargscaller.run ( zygoteinit.java:784)
06-16 18:09:50.232:e/androidruntime (10487): at Com.android.internal.os.ZygoteInit.main (zygoteinit.java:551)
06-16 18:09:50.232:e/androidruntime (10487): at Dalvik.system.NativeStart.main (Native Method)

Finally had to ask for help. StackOverflow issue when the webpage often problems, had to add QQ group, finally get Android Learning Exchange Group "Chengdu-young" point, finally solve the problem:

The 50th line of

Convertview
Get the layout file for the listview         Convertview = minflater.inflate (Com.hanvon.moniter.r.layout.site_list_item, null);

It is initialized in a 56-line if statement so that Convertview can initialize normally when NULL, instead of running 71 lines of code each time a value is initialized in advance.

Binding of//view
         if (Convertview = = null) {Convertview = minflater.inflate (com.hanvon.moniter.r.layout.site_ List_item, NULL);
}

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.