基于一些答案,在Fragments中添加了默认的构造函数,但仍然可以在游戏机上解决崩溃问题。
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3488)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3635)
at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:5582)
at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:5490)
at android.app.servertransaction.ActivityRelaunchItem.execute (ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2175)
at android.os.Handler.dispatchMessage (Handler.java:107)
at android.os.Looper.loop (Looper.java:237)
at android.app.ActivityThread.main (ActivityThread.java:7860)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075)
Caused by: androidx.fragment.app.Fragment$InstantiationException:
at androidx.fragment.app.Fragment.instantiate (Fragment.java:94)
at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java)
at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:9)
at androidx.fragment.app.FragmentStateManager.<init> (FragmentStateManager.java:10)
at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:96)
at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:8)
at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:17)
at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:10)
at com.companyname.activities.BaseActivity.onCreate (BaseActivity.java)
at com.companyname.activities.Activity1.onCreate (Activity1.java)
at android.app.Activity.performCreate (Activity.java:7955)
at android.app.Activity.performCreate (Activity.java:7944)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3463)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3635)
at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:5582)
at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:5490)
at android.app.servertransaction.ActivityRelaunchItem.execute (ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2175)
at android.os.Handler.dispatchMessage (Handler.java:107)
at android.os.Looper.loop (Looper.java:237)
at android.app.ActivityThread.main (ActivityThread.java:7860)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075)
Caused by: java.lang.NoSuchMethodException:
at java.lang.Class.getConstructor0 (Class.java:2332)
at java.lang.Class.getConstructor (Class.java:1728)
at androidx.fragment.app.Fragment.instantiate (Fragment.java:15)
at androidx.fragment.app.FragmentContainer.instantiate (FragmentContainer.java)
at androidx.fragment.app.FragmentManager$3.instantiate (FragmentManager.java:9)
at androidx.fragment.app.FragmentStateManager.<init> (FragmentStateManager.java:10)
at androidx.fragment.app.FragmentManager.restoreSaveState (FragmentManager.java:96)
at androidx.fragment.app.FragmentController.restoreSaveState (FragmentController.java:8)
at androidx.fragment.app.FragmentActivity.onCreate (FragmentActivity.java:17)
at androidx.appcompat.app.AppCompatActivity.onCreate (AppCompatActivity.java:10)
at com.companyname.activities.BaseActivity.onCreate (BaseActivity.java)
at com.companyname.activities.Activity1.onCreate (Activity1.java)
at android.app.Activity.performCreate (Activity.java:7955)
at android.app.Activity.performCreate (Activity.java:7944)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3463)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3635)
at android.app.ActivityThread.handleRelaunchActivityInner (ActivityThread.java:5582)
at android.app.ActivityThread.handleRelaunchActivity (ActivityThread.java:5490)
at android.app.servertransaction.ActivityRelaunchItem.execute (ActivityRelaunchItem.java:69)
at android.app.servertransaction.TransactionExecutor.executeCallbacks (TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2175)
at android.os.Handler.dispatchMessage (Handler.java:107)
at android.os.Looper.loop (Looper.java:237)
at android.app.ActivityThread.main (ActivityThread.java:7860)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075)
答案 0 :(得分:1)
您制作的构造函数没有任何参数吗?
例如,
public YourFragment() {
// Do not anything!!!
}