NullPointerException with SimpleCursorAdapter

混江龙づ霸主 提交于 2019-12-06 00:28:12

You are trying to access records via the cursor before it is pointing to a record. The code that is failing is most likely the second line of this snippet from your newView override.

   int nameCol = c.getColumnIndex("show_title");
   String name = c.getString(nameCol);
   TextView tv = (TextView) v.findViewById(R.id.textView1);

   if (name != null) {
       Log.e("GRIDVIEW", "I'm in here");
       tv.setText(name);
   }

You must not try to access field values from a cursor other than in bindView.

You should be able to get the column indexes in the contstructor of the adapter and store them as fields for later use in bindView.

newView should only be used to create a view.

Answer was from Herrmann - no need for a reference to the context and the cursor in my adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!