2015-11-12 62 views
0

棘手的问题。空指针异常与ExpandableListView

我有一个名为“Bivio”的类,其中我设置了一个Navigation Drawer,在第一个片段中有一个ExpandableListView。

我将ExpListView放入了fragment1中,并开发了Bivio.class中的所有活动。

然而,我在这一点上

expListView = (ExpandableListView) findViewById(R.id.lvExp); 

    prepareListData(); 

    listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild); 

    expListView.setAdapter(listAdapter); 

不用说,我确实有ID lvexp的ExpListView,我宣布所有因变量

ExpandableListAdapter listAdapter; 
ExpandableListView expListView; 
List<String> listDataHeader; 
得到我ExpListView一个NPE

Bivio.class在清单中声明。

这里是logcat的 http://pastebin.com/kFxjG5gR

我知道通过点击这个安全漏洞就出在这里 expListView.setAdapter(listAdapter)的链接; 但我尽我所能!

我猜navigationDrawer对嵌入在Fragments中的视图的主要活动中涉及的问题提出了一些挑战,是否正确?

回答

0
expListView = (ExpandableListView)findViewById(R.id.lvExp); 

如果在那里发生NPE,那么它必须意味着'findViewById'方法返回null。

+0

感谢KLIBBY。 我的ExpListView嵌入在一个片段的布局中,这有什么关系吗? – MDR

+0

我会在这里使用一个调试器来进入'findViewById'方法,并确定它为什么没有被设置。 – EkcenierK

+0

嗨Klibby刚刚启动,它没有提供任何回应,该应用程序在我的设备上启动,但无法加载导航抽屉所在的活动。有任何想法吗? :/需要logcat? – MDR