我有一个应用程序,它的工作正常,但当我在横向启动应用程序并回到肖像时,我的应用程序意外崩溃。这是错误日志。
10-13 22:18:33.913 9762 9762 E libEGL call to OpenGL ES API with no current context (logged once per thread)
10-13 22:18:39.163 9762 9762 E ViewRootImpl sendUserActionEvent() mView == null
10-13 22:18:39.253 9762 9762 E ViewRootImpl sendUserActionEvent() mView == null
10-13 22:18:39.323 9762 9762 E AndroidRuntime FATAL EXCEPTION: main
10-13 22:18:39.323 9762 9762 E AndroidRuntime Process: com.androbaron.materialnews, PID: 9762
10-13 22:18:39.323 9762 9762 E AndroidRuntime java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context android.view.ViewGroup.getContext()' on a null object reference
10-13 22:18:39.323 9762 9762 E AndroidRuntime at android.support.design.widget.Snackbar.<init>(Snackbar.java:180)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at android.support.design.widget.Snackbar.make(Snackbar.java:209)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at com.androbaron.materialnews.fragment.RecipesFragment.onRefresh(RecipesFragment.java:162)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at com.androbaron.materialnews.fragment.RecipesFragment.access$1000017(RecipesFragment.java)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at com.androbaron.materialnews.fragment.RecipesFragment$100000000.run(RecipesFragment.java:61)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at android.os.Handler.handleCallback(Handler.java:739)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at android.os.Handler.dispatchMessage(Handler.java:95)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at android.os.Looper.loop(Looper.java:148)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at android.app.ActivityThread.main(ActivityThread.java:7325)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at java.lang.reflect.Method.invoke(Native Method)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
10-13 22:18:39.323 9762 9762 E AndroidRuntime at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
修改
我目前发现它只能在Fregment
中使用,但在Activity
中正常工作。
问题已修复。
我可以改变
android:configChanges="orientation|screenSize"
每个<Activity
android:configChanges="orientation|keyboardHidden|screenSize"
答案 0 :(得分:0)
将此添加到您的清单
<activity android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize" >