我在尝试运行我的应用程序时遇到了一些错误这里是 logcat java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.chatapp/com.example.chatapp.MainActivity}: java.lang.InstantiationException: java.lang.Class<com.example.chatapp.MainActivity> has no zero argument constructor at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2843) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) at android.os.Handler.dispatchMessage(Handler.java:106) 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) Caused by: java.lang.InstantiationException: java.lang.Class<com.example.chatapp.MainActivity> has no zero argument constructor这是我的 mainAcivity `public class MainActivity extends AppCompatActivity {Button login, register;FirebaseUser firebaseUser;@Overrideprotected void onStart() { super.onStart(); firebaseUser = FirebaseAuth.getInstance().getCurrentUser(); //check if user in null if (firebaseUser != null){ Intent intent = new Intent(MainActivity.this, Main2Activity.class); new MainActivity(intent); finish(); }}`但我也认为这是一个错误 public MainActivity(Intent intent) {}
1 回答
眼眸繁星
TA贡献1873条经验 获得超9个赞
活动不需要实例化,因此只需要调用以下内容即可启动:
//check if user in null
if (firebaseUser != null){
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
finish();
}
基本上你只需要删除这一行:
new MainActivity(intent);
并开始活动:
startActivity(intent);
添加回答
举报
0/150
提交
取消