Reputation: 13
TextView drawerName = (TextView) findViewById(R.id.drawerName);
TextView drawerEmail = (TextView) findViewById(R.id.drawerEmail);
CircleImageView drawerAvatar = (CircleImageView) findViewById(R.id.drawerAvatar);
drawerName.setText(personName);
drawerEmail.setText(personEmail);
FATAL EXCEPTION: main Process: com.mje.dev.liqourstore, PID: 1537 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mje.dev.liqourstore/com.mje.dev.liqourstore.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3149) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3248) at android.app.ActivityThread.access$1000(ActivityThread.java:197) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6872) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.mje.dev.liqourstore.MainActivity.onCreate(MainActivity.java:146) at android.app.Activity.performCreate(Activity.java:6550) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3102) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3248) at android.app.ActivityThread.access$1000(ActivityThread.java:197) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1681) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:6872) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Upvotes: 0
Views: 1952
Reputation: 13
TextView drawerName = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navDrawerName);
TextView drawerEmail = (TextView) navigationView.getHeaderView(0).findViewById(R.id.navDrawerEmail);
CircleImageView drawerAvatar = (CircleImageView) navigationView.getHeaderView(0).findViewById(R.id.avatar);
Upvotes: 0
Reputation: 2790
It looks like that you haven't set the View
of Activity
by setting contentView as setContentView
. Furthermore, please also check that setContentView
layout also have the textview
you are fetching.
hope this helps.
Upvotes: 0