0

Tricky question.

I have a class named "Bivio" in which I set a Navigation Drawer and in the first of the fragments there is an ExpandableListView.

I placed the ExpListView in fragment1 and develop all the activities from Bivio.class.

Yet, I get a NPE on my ExpListView at this point

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

    prepareListData();

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

    expListView.setAdapter(listAdapter);

It goes without saying that I actually have an ExpListView with ID lvexp, that I declared all the due variables

ExpandableListAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;

Bivio.class is declared in manifest.

And here is the logcat http://pastebin.com/kFxjG5gR

I know by clicking on the link that the flaw lies in here expListView.setAdapter(listAdapter); but I declared all I could!

I guess navigationDrawer poses some challenges for what concerns working in the main activity on Views embedded in Fragments, correct?

MDR
  • 55
  • 7

1 Answers1

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

If the NPE occurs there then it must mean that the 'findViewById' method is returning null.

EkcenierK
  • 1,429
  • 1
  • 19
  • 34
  • thanks KLibby. My ExpListView is embedded in the layout of a fragment, does it matter? – MDR Nov 12 '15 at 07:48
  • I would use a debugger at this point to step into the `findViewById` method and find out for sure why it's not being set. – EkcenierK Nov 12 '15 at 07:51
  • Hi Klibby just launched and it gives nothing back, the app starts off on my device but can't load the activity where the Navigation Drawer is. Any ideas? :/ Need the logcat? – MDR Nov 12 '15 at 07:56
  • 11-12 00:05:26.343 8233-8233/yo.tantebestemmie E/AndroidRuntime: `Caused by: java.lang.NullPointerException 11-12 00:05:26.343 8233-8233/yo.tantebestemmie E/AndroidRuntime: at yo.tantebestemmie.Bivio.onCreate(Bivio.java:74)` This appears to be the root cause. You need to set some breakpoints here, figure out what variable is null and trace back until you find out why. Check this [answer](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) - there is usually a common set of steps needed to debug any null pointer exception. – EkcenierK Nov 12 '15 at 08:49