Reputation: 3007
This may be a bit hard to explain but here goes. First you need to know how my app is set up.
LoginPage > ViewPager tutorial (contains 4 fragments) > Navigation drawer.
On the last Fragment in the ViewPager there's a button to confirm you have completed the tutorial. The problem comes about when you want to see the tutorial again. I added it into my navigation drawer because I wanted users to be able to go back to the tutorial. I get a force close error when the users presses the button on the 4th Fragment saying they have seen the tutorial. This error only happens when going to the tutorial for a second time, through the navigation drawer.
Here is how you get to it:
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Fragment newFragment = new FragmentOne();
FragmentManager fm = getSupportFragmentManager();
switch(i) {
case 0:
newFragment = new FragmentTwo();
fm.popBackStack();
fm.beginTransaction().add(R.id.main, newFragment).addToBackStack("fragback").commit();
break;
case 1:
newFragment = new FragmentThree();
fm.popBackStack();
fm.beginTransaction().add(R.id.main, newFragment).addToBackStack("fragback").commit();
break;
case 2:
newFragment = new FragmentFour();
fm.popBackStack();
fm.beginTransaction().add(R.id.main, newFragment).addToBackStack("fragback").commit();
break;
case 3:
Intent goToTut = new Intent(getApplicationContext(), FragmentPagerActivity.class);
startActivity(goToTut);
//fm.popBackStack();
break;
}
drawerLayout.closeDrawer(rl);
case 3:
Intent goToTut = new Intent(getApplicationContext(), FragmentPagerActivity.class);
startActivity(goToTut);
The error:
FATAL EXCEPTION: main
Process: com.package.name, PID: 3379
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.inter.space.NavDrawer}:
java.lang.NullPointerException: println needs a message
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
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:5017)
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:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.i(Log.java:160)
at com.package.name.PostLogin.onCreate(PostLogin.java:98)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
01-29 10:20:08.852: E/AndroidRuntime(3379): ... 11 more
I think the error is because I am trying to open the NavigationDrawer from a different place where it tries to create a new instance of it when really, it's already running. Is there a way that I can solve this issue?
I would really appreciate some help on this, because I am lost. Thank you in advance.
Upvotes: 1
Views: 189
Reputation: 133570
From your comments line 98 is
Log.i("Facebook id:", pId);
So pld
is null. You log says that needs a message to print.
Caused by: java.lang.NullPointerException: println needs a message
Check and make sure pld
is not null
Upvotes: 1