Error series for Android development (1), java. lang. NullPointerException, at android. widget. ListView. setupChild, appwidgetlistview

Source: Internet
Author: User

Error series for Android development (1), java. lang. NullPointerException, at android. widget. ListView. setupChild, appwidgetlistview

Problem description: The Running code reports a null pointer error, java. lang. NullPointerException, at Android. widget. ListView. setupChild

Problem location: The listview control reports an error. The cause of the query is correct. If an error occurs when the adapter sets the item value, check the code. The error is returned here.

When the item value of the adapter is set, due to carelessness, return convertView is returned as return null for the first time, leading to the above error.

1 public class CasesAdapter extends NormalListAdapter <Cases> {2 private ViewHolder viewHolder = null; 3 private Context mCtc; 4 private static class ViewHolder {5 public ImageView aImg; 6 public TextView aTitle; 7 public TextView aHits; 8 public TextView aTime; 9} 10 public CasesAdapter (Context context, List <Cases> item) {11 super (context, item ); 12 // TODO Auto-generated constructor stub13 mCtc = context; 14} 15 16 @ Override17 public View getView (int position, View convertView, ViewGroup parent) {18 // judge whether the attempt is null 19 if (convertView = null) {20 // if the attempt is null, load the attempt page 21 convertView = inflater. inflate (R. layout. list_item_cases, null); 22 // instantiate ViewHolder23 viewHolder = new ViewHolder (); 24 // set the control 25 viewholder corresponding to the element in viewHolder. aImg = (ImageView) convertView. findViewById (R. id. imgs); 26 viewHolder. aTitle = (TextView) convertView. findViewById (R. id. msg_title); 27 viewHolder. aHits = (TextView) convertView. findViewById (R. id. msg_hit); 28 viewHolder. aTime = (TextView) convertView. findViewById (R. id. msg_time); 29 convertView. setTag (viewHolder); 30} 31 else {32 viewHolder = (ViewHolder) convertView. getTag (); 33} 34 Cases cs = itemContent. get (position); 35 // set the value 36 viewHolder bound to the control. aTitle. setText (cs. getTitle (); 37 viewHolder. aHits. setText (cs. getHits (); 38 viewHolder. aTime. setText (cs. getAddtime (); 39 // The Network asynchronously loads 40 ImageLoader. getInstance (). displayImage ("http: // 192.168.2.26: 8012" + cs. getFilename (), 41 viewHolder. aImg, Define. options1, 42 new AnimateFirstDisplayListener (); 43 return null; // The error is returned, causing an exception 44} 45 46}

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.