5-4作业运行报错

5-4作业运行报错

先做的显示部分,报错信息和代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
public class DBAdapter extends CursorTreeAdapter {
    Context mContext;
    public DBAdapter(Cursor groupCursor, Context context) {
        super(groupCursor, context);
        mContext = context;
    }
 
 
    @Override
    protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {
        TextView  groupView = new TextView(context);
        return groupView;
 
    }
 
    @Override
    protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {
        String type = cursor.getString(2);
        TextView groupView=(TextView) view;
        groupView.setText(type);
    }
 
    @Override
    protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {
        TextView childView=new TextView(context);
        return childView;
    }
 
    @Override
    protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {
        String name=cursor.getString(1);
        TextView childView=(TextView)view;
        childView.setText(name);
        childView.setPadding(30,0,0,0);
    }
    @Override
    protected Cursor getChildrenCursor(Cursor groupCursor) {
        return groupCursor;
    }
}
 
public class MainActivity extends AppCompatActivity {
    ContentResolver resolver;
    ExpandableListView foodList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Cursor dataCursor=getData();
        foodList=findViewById(R.id.food_list);
        foodList.setAdapter(new DBAdapter(dataCursor,MainActivity.this));
 
    }
 
    private Cursor getData() {
        resolver=getContentResolver();
        Uri uri= Uri.parse("content://com.imooc.menuprovider");
        Cursor c = resolver.query(uri,null,null,null,null);
        return c;
    }
}

http://img1.sycdn.imooc.com//climg/5b250676000165ba28860766.jpg

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕雪 2018-06-17 18:38:41

你得到crusor后先判断一下它,是不是没得到数据。检查一下作业素材提供的APP安装上了没有。

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码