简体   繁体   中英

How can I know what threw the exception?

First I just got to say, I know how to find my exception usually. But I encountered a situation where the stackstrace doesn't show any of my classes but only library classes.

I've tried debugging the code without success.

This is the stack trace

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.ys571.realdeal, PID: 11175
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
    at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:396)
    at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:391)
    at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:107)
    at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1010)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1224)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1092)
    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1622)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
    at android.view.View.measure(View.java:23169)
    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:716)
    at android.view.View.measure(View.java:23169)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2718)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1572)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1855)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
    at android.view.Choreographer.doCallbacks(Choreographer.java:761)
    at android.view.Choreographer.doFrame(Choreographer.java:696)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

It is the stack trace when I'm trying to move from my main activity to another activity using my navigation drawer. It was terminated probably after the new activity onResume. I can't know exactly from what and where.

Thanks!

It looks like it's something to do with the ViewPager . I'm assuming in your new activity you have a ViewPager and I'm guessing it isn't getting instantiated correctly. Check out this question which seems to have the same problem and offers a few solutions.

If you use Android Studio, then you can use Exception Breakpoint while debugging. Here is a link that you can see the example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM