last day (14 days later) » 

2:13 AM
0
A: Nullpointer with navigation drawer. Not detecting value assignments

N1toYou need to set proper id in your XML for your ListView - android:id="@+id/left_drawer", which is the same as id are you referring in OnCreate, it causes your error. Anyway, your implementation is wrong. Please read how to do it properly. Here it is great explained how to do this - link <Rela...

 
I do set the proper id in the mDrawerList = (ListView) findViewById(R.id.left_drawer); line don't I?
 
No. In your xml you set android:id="@android:id/list", while in code you want find this view by id left_drawer, not list. So you must change in xml to android:id="@+id/left_drawer"
 
In the rest of my project I am pulling and parsing a json response that populates the main activity in a list view. The listview that I am using for the drawer is in a drawer_layout.xml file. Regardless, i wouldn't be getting a nullpointer error for both of the mentioned values.
 
Look. You are setting layout for MainActivity using function setContentView(R.layout.activity_main); in onCreate. Then you are trying to get reference to widget mDrawerList = (ListView) findViewById(R.id.left_drawer); . It starts searching for item with id left_drawer in activity_main.xml, but it won't find because it does not exist in this layout.
 
Ok i see what you are saying. Let me add my edited code and give a better context
So originally my drawer_layout wasn't in my activity_main which I discovered had to be. I put it in there so now I have both ListViews, the one that populates the main layout and the one that populates the drawer layout. Still get the same error though.
 
2:13 AM
DrawerLayout only supports two child views.
hello
 
Like I said, DrawerLayout only supports two child views.
 
so where else place it?
 
You need 3 items in DrawerLayout?
 
in the tutorial on the developers site, it says to have it as the rootview for whatever activity you are in
 
2:19 AM
You can place as many as you want items activity_main.xml
but DrawerLayout must have 2 childs only
 
so how would i go about better structuring it?
 
I will show you example
 
you must put your UI inside RelativeLayout
first child is for MainActivity ui, which you want - these two inside RelativeLayout
second child, ListView, is navigation
now it works? :)
are you there?
 
yes. sorry. i was applying ur changes
it doesn't work:(
 
2:32 AM
what problem now?
 
let me re start my android studio
it's the same problem
but it says it's on a line that has nothing on it
one second
 
still nullpointer expection?
 
awesome
i restarted it and it no longer give me the error
thanks for being so patient:)
 
so it works now or just don't give error?
;)
 
well it doesn't work on genymotion, but I'm about to test on my phone. If you want, copy past that exact same pastebin code that you showed me as a response, and I'll mark it as the solution
 
2:37 AM
ok, sec
done
tell if everything OK on phone
 
ok, one second
awesome. it works
 
^.^
 
thanks alot!
 
so you can up-vote it and mark as answered
ieie ;)
 
yes. I'll go do that:)
 
2:44 AM
time to sleep
its 4:44 am in Poland ;)
good night :)
 

last day (14 days later) »