0

I'm having reasonable success with notifications and fragments in my Android App although occasionally I get an error, as shown below, in my Firebase error log

Although it rarely occurs, about 5-6 per 10,000 notifications over 3 months to the app, it is a bit annoying because the notification is lost (maybe that's an acceptable level of crashes!)

I'd love to fix it in my code if I could, but I don't quite understand what this log is telling me

Does it mean anything to you..? Any help appreciated

NullPointerException - FragmentManagerImpl.execSingleAction

Exception java.lang.NullPointerException:

android.support.v4.app.FragmentManagerImpl.execSingleAction (FragmentManager.java:1623)
android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss (BackStackRecord.java:637)
android.support.v4.app.FragmentPagerAdapter.finishUpdate (FragmentPagerAdapter.java:143)
android.support.v4.view.ViewPager.setAdapter (ViewPager.java:511)
com.support.android.policeman.MainActivity.setupViewPager (MainActivity.java:156)
com.support.android.policeman.MainActivity.refreshFragments (MainActivity.java:454)
com.support.android.policeman.MainActivity$7.run (MainActivity.java:425)
android.os.Handler.handleCallback (Handler.java:730)
android.os.Handler.dispatchMessage (Handler.java:92)
android.os.Looper.loop (Looper.java:176)
android.app.ActivityThread.main (ActivityThread.java:5419)
java.lang.reflect.Method.invokeNative (Method.java)
java.lang.reflect.Method.invoke (Method.java:525)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1046)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:862)
dalvik.system.NativeStart.main (NativeStart.java) 

Ok, so I'm a bit of a novice. However, thanks @altskop for the tip on how to understand this log and below is the bit of code where it is throwing the fatal error (viewPager.setAdapter(adapter) is line 156 to be exact)

private void setupViewPager(ViewPager viewPager) {
    Adapter adapter = new Adapter(getSupportFragmentManager());
    adapter.addFragment(new SenderListFragment(), "Loopy");
    adapter.addFragment(new MessageListFragment(), "Poopy");
    adapter.addFragment(new ContactListFragment(), "Scoopy");
    viewPager.setAdapter(adapter);
}

Is there a reason why the new adapter create wouldn't work, and if it returns null, what can I do..?

rangi
  • 361
  • 2
  • 4
  • 21

1 Answers1

0

What does this particular method .MainActivity.setupViewPager (MainActivity.java:156) do in your app? I'd guess it accesses some variable, and according to the log, occasionally this variable isn't initialized, which throws the NullPointerException. Check the operations you perform on it and make sure that it's always initialized prior to being called.

altskop
  • 311
  • 2
  • 12
  • Thank you very much altskop for your useful tip, I wasn't sure where to start looking for the problem. I've added a bit of code at the line position indicated to my question, maybe that narrows things down. – rangi Jun 24 '17 at 21:46
  • Check out [this](https://stackoverflow.com/questions/25748610/android-getsupportfragmentmanager-null-pointer-exception-in-fragment) thread, I think it has the solution to your problem. – altskop Jun 26 '17 at 02:48