My app is getting a couple exceptions when I rotate my phone and my progress dialog (DialogFragment) is visible. Not quite sure if I’m following the correct process for creating and dismissing a dialog fragment. If I don’t rotate my phone when the dialog is up, everything is fine.
I create and show the dialog in onCreate()
progressDialog.show(getSupportFragmentManager(),"123");
and start a background thread to load data from a server. Once the data is loaded I call the dialog’s dismiss() (using runOnUiThread(() -> {progressDialog.dismiss(); }); to stay thread safe, but note that it never gets called because I rotate and get an exception before the thread finishes). I also call the dialogs dismiss() in onStop().
I see this more often: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment myapp.ProgressDialog: could not find Fragment constructor
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: myapp, PID: 19953
java.lang.RuntimeException: Unable to start activity ComponentInfo{myapp/myapp.GameListActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment myapp.ProgressDialog: could not find Fragment constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3654)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5802)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710)
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:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment myapp.ProgressDialog: could not find Fragment constructor
at androidx.fragment.app.Fragment.instantiate(Fragment.java:563)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:390)
at androidx.fragment.app.FragmentStateManager.<init>(FragmentStateManager.java:74)
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2452)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:196)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:287)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
--> at myapp.GameListActivity.onCreate(GameListActivity.java:87)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5802)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710)
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:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.NoSuchMethodException: myapp.ProgressDialog.<init> []
at java.lang.Class.getConstructor0(Class.java:2332)
at java.lang.Class.getConstructor(Class.java:1728)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:548)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:390)
at androidx.fragment.app.FragmentStateManager.<init>(FragmentStateManager.java:74)
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2452)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:196)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:287)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)
at myapp.GameListActivity.onCreate(GameListActivity.java:87)
at android.app.Activity.performCreate(Activity.java:7963)
at android.app.Activity.performCreate(Activity.java:7952)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5802)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710)
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:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
I/Process: Sending signal. PID: 19953 SIG: 9
Disconnected from the target VM, address: 'localhost:8624', transport: 'socket'
But have also seen java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState when I’m trying to dismiss a fragment dialog (a progress dialog).
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: myapp, PID: 11658
java.lang.RuntimeException: Unable to stop activity {myapp/myapp.GameListActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5125)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5775)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710)
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:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
at androidx.fragment.app.FragmentManager.checkStateLoss(FragmentManager.java:1689)
at androidx.fragment.app.FragmentManager.enqueueAction(FragmentManager.java:1729)
at androidx.fragment.app.BackStackRecord.commitInternal(BackStackRecord.java:321)
at androidx.fragment.app.BackStackRecord.commit(BackStackRecord.java:286)
at androidx.fragment.app.DialogFragment.dismissInternal(DialogFragment.java:270)
at androidx.fragment.app.DialogFragment.dismiss(DialogFragment.java:222)
--> at myapp.GameListActivity.onStop(GameListActivity.java:167)
at android.app.Instrumentation.callActivityOnStop(Instrumentation.java:1474)
at android.app.Activity.performStop(Activity.java:8195)
at android.app.ActivityThread.callActivityOnStop(ActivityThread.java:5117)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5775)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5710)
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:2267)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
This is my dialog fragment:
public class ProgressDialog extends DialogFragment {
public static final String TAG="lbp";
String message;
ProgressBar progressBar;
TextView progressMessage;
public ProgressDialog(String msg) {
this.message = msg;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View dlgView = inflater.inflate(R.layout.progress,null);
progressBar = dlgView.findViewById(R.id.progressBar);
progressMessage = dlgView.findViewById(R.id.progressMessage);
progressMessage.setText(message);
builder.setView(dlgView);
return builder.create();
}
public void setMessage(CharSequence msg) {
progressMessage.setText(msg);
}
}
Related
captureImageIntentLauncher.launch(intent);
ActivityResultLauncher<Intent> captureImageIntentLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
#Override
public void onActivityResult(ActivityResult result) {
Logger.e("res", String.valueOf(result.getResultCode()));
if (result.getResultCode() == Activity.RESULT_OK) {
// There are no request codes
compressImage(photoFile);
}
}
});
2022-08-21 23:31:50.915 19538-19538/com.edgewise.handheld.easyapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.edgewise.handheld.easyapp, PID: 19538
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.edgewise.handheld.easyapp/com.edgewise.handheld.easyapp.NewReturnActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.edgewise.handheld.easyapp.fragments.ReturnScanSkuFragment: could not find Fragment constructor
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3271)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.edgewise.handheld.easyapp.fragments.ReturnScanSkuFragment: could not find Fragment constructor
at androidx.fragment.app.Fragment.instantiate(Fragment.java:628)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
at androidx.fragment.app.FragmentStateManager.(FragmentStateManager.java:85)
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198)
at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.edgewise.handheld.easyapp.NewReturnActivity.onCreate(NewReturnActivity.java:23)
at android.app.Activity.performCreate(Activity.java:7825)
at android.app.Activity.performCreate(Activity.java:7814)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
Caused by: java.lang.NoSuchMethodException: com.edgewise.handheld.easyapp.fragments.ReturnScanSkuFragment. []
at java.lang.Class.getConstructor0(Class.java:2332)
at java.lang.Class.getConstructor(Class.java:1728)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:613)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57)
at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483)
at androidx.fragment.app.FragmentStateManager.(FragmentStateManager.java:85)
at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728)
at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198)
at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.edgewise.handheld.easyapp.NewReturnActivity.onCreate(NewReturnActivity.java:23)
at android.app.Activity.performCreate(Activity.java:7825)
at android.app.Activity.performCreate(Activity.java:7814)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3246)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2017)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
I am trying to initialize TextView in Kotlin as following
val textSelectedFood = findViewById<TextView>(R.id.textSelectedFood) as TextView
I also tried this
val textSelectedFood: TextView = findViewById<TextView>(R.id.textSelectedFood) as TextView
And also this
val textSelectedFood: TextView = findViewById(R.id.textSelectedFood) as TextView
And this
val textSelectedFood: TextView = findViewById<TextView>(R.id.textSelectedFood)
But still getting following errors. Don't know why
2021-01-10 23:38:26.640 29636-29636/com.imran.android.dinnerdecider E/d.dinnerdecide: Unknown bits set in runtime_flags: 0x8000
2021-01-10 23:38:27.091 29636-29636/com.imran.android.dinnerdecider E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.imran.android.dinnerdecider, PID: 29636
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.imran.android.dinnerdecider/com.imran.android.dinnerdecider.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:163)
at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:174)
at android.content.Context.obtainStyledAttributes(Context.java:738)
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:839)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:806)
at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:630)
at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:223)
at com.imran.android.dinnerdecider.MainActivity.<init>(MainActivity.kt:12)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1243)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3182)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I got hints from this question.
but the code changed a lot over the year.
That's why I am writing the current solution code in the below which solved my problem.
private lateinit var textSelectedFood: TextView // withoud lateinit code will show error
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textSelectedFood = findViewById(R.id.textSelectedFood)
}
If you do not have to "findViewById" have many better and safer options:
1.synthetic (deprecated)
Call the view directly in your code.
2.view binding
For more information check this link:https://developer.android.com/topic/libraries/view-binding
This technique is old now, just use "View binding".
Or you can just call the view by it's id and that'll be it.
In your case:
textSelectedFood.text = "Example of doing something"
I have been developing an app for android and ios using React Native 0.60.4, and just recently I discovered that putting the app in split-screen or freeform mode (from being the only app on the screen) sometimes causes it to crash.
I played with this further and found that I can launch the app into split screen or freeform mode with no problem, but sometimes resizing it will cause it to crash. Below is the output from my debugger instance in Android Studio, which I'm struggling to make sense of:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myApp, PID: 32150
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myApp/com.myApp.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.Screen$ScreenFragment: calling Fragment constructor caused an exception
at androidx.fragment.app.Fragment.instantiate(Fragment.java:465)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:50)
at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:80)
at androidx.fragment.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109)
at androidx.fragment.app.FragmentController.restoreAllState(FragmentController.java:158)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:344)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:443)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:50)
at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:80)
at androidx.fragment.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109)
at androidx.fragment.app.FragmentController.restoreAllState(FragmentController.java:158)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:344)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalStateException: Screen fragments should never be restored
at com.swmansion.rnscreens.Screen$ScreenFragment.<init>(Screen.java:24)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at androidx.fragment.app.Fragment.instantiate(Fragment.java:443)
at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:50)
at androidx.fragment.app.FragmentState.instantiate(FragmentState.java:80)
at androidx.fragment.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:3109)
at androidx.fragment.app.FragmentController.restoreAllState(FragmentController.java:158)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:344)
at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:85)
at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:51)
at android.app.Activity.performCreate(Activity.java:7802)
at android.app.Activity.performCreate(Activity.java:7791)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1299)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5279)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5187)
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:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Add this to your MainActivity.java
import android.os.Bundle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
}
In MainActivity.java add
import android.os.Bundle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
}
Explanation: https://github.com/software-mansion/react-native-screens#android
Example:
package com.example_app;
import android.os.Bundle; // required for onCreate parameter
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
#Override
protected String getMainComponentName() {
return "example_app";
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
}
#Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
#Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
}
Just another approach:
context.supportFragmentManager.addFragmentOnAttachListener { _,_ -> context.savedStateRegistry.unregisterSavedStateProvider("android:support:fragments")}
GoodDay everybody.
I wrote a class which extends AsyncTask.
public class InitTransaction extends AsyncTask<TransactionParameters, Void, String> {
#Override
protected String doInBackground(TransactionParameters... params) {
// I do some stuff here
return result;
}
#Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// I do some more stuff
}
}
The class is called with:
TransactionParameters transParams = new TransactionParameters(param1, param2);
InitTransaction initTransaction = new InitTransaction();
initTransaction.execute(transParams);
The problem is that i get an error while passing the object to the task:
[![No method?][1]][1]
Anybody knows where the problem may be?
EDIT
Fixed that problem now I have another one.
As soon as I execute initTransaction.execute(transParams); boom!
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.infovision.elcam_02, PID: 17443
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:6600)
at android.view.View.performClickInternal(View.java:6577)
at android.view.View.access$3100(View.java:781)
at android.view.View$PerformClick.run(View.java:25912)
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:6923)
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:870)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:6600)
at android.view.View.performClickInternal(View.java:6577)
at android.view.View.access$3100(View.java:781)
at android.view.View$PerformClick.run(View.java:25912)
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:6923)
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:870)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:828)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.app.Dialog.show(Dialog.java:329)
at com.infovision.elcam_02.MainActivity$InitTransaction.onPreExecute(MainActivity.java:242)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:648)
at android.os.AsyncTask.execute(AsyncTask.java:595)
at com.infovision.elcam_02.MainActivity.scanCode(MainActivity.java:133)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:6600)
at android.view.View.performClickInternal(View.java:6577)
at android.view.View.access$3100(View.java:781)
at android.view.View$PerformClick.run(View.java:25912)
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:6923)
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:870)
This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 4 years ago.
I am trying to pass login details to another class so that it can be used to login on my MySQL db (using php) but it is crashing giving me the exception: java.lang.IllegalStateException: Could not execute method for android:onClick
stack trace: {StackTraceElement[0]#5692}
658 10752-10752/uk.ac.abertay.contactslist E/AndroidRuntime: FATAL EXCEPTION: main
Process: uk.ac.abertay.contactslist, PID: 10752
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:293)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void uk.ac.abertay.contactslist.Login.Logino(uk.ac.abertay.contactslist.LoginDetails)' on a null object reference
at uk.ac.abertay.contactslist.LoginActivity.Loginbutton(LoginActivity.java:40)
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
04-26 15:39:34.761 1384-3633/? I/chatty: uid=1041(audioserver) writer identical 8 lines
this is the code for the button
private Login login;
public void Loginbutton(View v) {
/* Get entered fields data. */
String email = field_email.getText().toString();
String password = field_password.getText().toString();
login.Logino(new LoginDetails(email,password));
}
when debugging it will run this and go back to the button and after that it will give the exception and crash
public class LoginDetails {
public String email = "";
public String password = "";
LoginDetails(String e, String p) {
email = e;
password = p;
}
}
this is the code I'm trying to run with the button above
public void Logino(LoginDetails loginDetails) {
LoginTask task = new LoginTask();
task.execute(loginDetails);
}
From your StackTrace
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void uk.ac.abertay.contactslist.Login.Logino(uk.ac.abertay.contactslist.LoginDetails)
The line login.Logino the object login is null, you have to initialize it.
Obs:Please use Java naming conventions with method names starting with low case char.