This question has already been answered:

What could be the problem?

FATAL EXCEPTION: main Process: com.happ, PID: 24333 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.happ/com.happ.controllers.FeedActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.happ.controllers.FeedActivity.onCreate(FeedActivity.java:182) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) 

Here swears on this line:

 navigationView.getMenu().findItem(R.id.nav_item_feed).setChecked(true); 

Here is the markup:

 <android.support.design.widget.NavigationView xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/navigation_view" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" android:overScrollMode="ifContentScrolls"> <android.support.design.widget.NavigationView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" app:headerLayout="@layout/drawer_header"/> <android.support.design.widget.NavigationView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" app:menu="@menu/drawer"/> </android.support.design.widget.NavigationView> 

PS I still need to figure out how to properly substitute a menu drawer under the drawer_header . I just want to insert a ViewPager between the menu drawer and the drawer_header ViewPager . Do not tell RelatievLayout how this can be done in NavigationView , to substitute the functions below and above as in RelatievLayout .

Reported as a duplicate by Vladyslav Matviienko android Oct 13 '16 at 15:09 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Add full activity code. - post_zeew
  • @metalurgus I know what nullpointer is, I did not understand why I got it. + to everything, there is another question about the viewpager and I don’t think it is a duplicate. + I found a solution to my problem with ViewPager. And how can you insert anything between the menu and the tip. - Satanist Devilov
  • еще один вопрос your еще один вопрос into a separate question as it should be - Vladyslav Matviienko

1 answer 1

You fall because you try to get the menu before it loads, which takes place in onCreateOptionsMenu. You need to manipulate not earlier than onCreateOptionsMenu or onPrepareOptionsMenu.

To insert a NavigationView into a NavigationView is completely unclear why.

Add something under the header - just add it to the header itself

  • I need to understand how I can insert between headerLayout and menu - viewpager. - Satanist Devilov