大神进,帮我看下这个异常,困扰一天(新手)

qq2201181566 2017-07-20 03:27:40
LinearLayout resultDialog = (LinearLayout)getLayoutInflater().inflate(R.layout.result,null,false);
ExpandableListView list = (ExpandableListView) resultDialog.findViewById(R.id.result_list);

回报出空指针:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference
我查询了一下list是null,上面两句是写在button的onclick里面的,result_list是可以找到的,是个expandable listview
...全文
264 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lytton_jing 2017-07-21
  • 打赏
  • 举报
回复
顶起来,学习中 http://blog.csdn.net/ddjj_1980/article/details/74940593
game_dream 2017-07-21
  • 打赏
  • 举报
回复
你检查下你list哪里出问题了,看看resultDialog是不是null。或者布局文件id的问题?检查下,贴下R.layout.result这个布局文件代码
qq2201181566 2017-07-20
  • 打赏
  • 举报
回复

            Button btn = (Button) findViewById(R.id.search);
            btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            .......

                LinearLayout resultDialog = (LinearLayout)getLayoutInflater().inflate(R.layout.result,null,false);
                ExpandableListView list = (ExpandableListView) resultDialog.findViewById(R.id.result_list);

                ExpandableListAdapter adapter = new BaseExpandableListAdapter() {.........};

                list.setAdapter(adapter);//提示这一句有错

           ......
           }
code小生 2017-07-20
  • 打赏
  • 举报
回复
应该是你的 resultDialog 加载布局问题,换个方式,或者把上面的 第二个参数不要设置为 Null
Dianliang_ 2017-07-20
  • 打赏
  • 举报
回复
引用 楼主 qq2201181566 的回复:
LinearLayout resultDialog = (LinearLayout)getLayoutInflater().inflate(R.layout.result,null,false);
                ExpandableListView list = (ExpandableListView) resultDialog.findViewById(R.id.result_list);
回报出空指针: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ExpandableListView.setAdapter(android.widget.ExpandableListAdapter)' on a null object reference 我查询了一下list是null,上面两句是写在button的onclick里面的,result_list是可以找到的,是个expandable listview
代码贴出来,是不是获取id前面进行操作了?

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧