문제

Although for a phone I will use the same layout regardless of orientation, for a tablet I have one layout for portrait and one for landscape, so ignoring configuration changes is not the optimal solution.

Things become more complicated when the scenario is like this-

  1. On Landscape orientation, clicked the tab 1 that showed the fragment 1 (left side) and fragment 2 (right side). The fragment 2 contains button 1.

  2. Then clicked the button 1 that opened the dialog fragment (right side) while tab 1 with fragment 1 (left side) and fragment 2 (right side) still in opened state.

  3. Rotated the device to portrait orientation and application crashed.

The intent is to open only the dialog fragment (which was opened in landscape) in portrait.

Run debugger which ran all the required methods. This doesn't reveal that where is the NullPointerException.

The stack trace is not pointing exact method of error -

    fatal error : null
    java.lang.NullPointerException?    
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1419)?    
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)?    
    at android.os.Handler.handleCallback(Handler.java:615)?    
    at android.os.Handler.dispatchMessage(Handler.java:92)?    
    at android.os.Looper.loop(Looper.java:137)?    
    at android.app.ActivityThread.main(ActivityThread.java:4953)?    
    at java.lang.reflect.Method.invokeNative(Native Method)?    
    at java.lang.reflect.Method.invoke(Method.java:511)?    
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)?    
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)?    
    at dalvik.system.NativeStart.main(Native Method)

Any way ?

도움이 되었습니까?

해결책

This may help someone who may face a similar error:

After performing a series of test cases to find out the root cause of this crash, finally it was one line in the code that was the culprit.

And the line was -

@Override
public void onDestroy()
{
    super.onDestroy();  
    tap.getEntriesByRule(view); // Culprit
}

Explanation:

The problem with this line is----

IT MESSED UP THE PENDING TRANSACTION.

While you are at fragment fragNoPop and when you rotate the device, you goes to fragment fragPop.

In fragPop, we have a culprit onDestroy() which again redirects to fragNoPop with a call to tap.getEntriesByRule(view); which is already destroyed on rotation. So now it is attached again causing a mess.

One line was enough for causing errors like execPendingActions.

So first check such activity methods before anything else. Beware!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top