面临主要活动困难

我在尝试运行我的应用程序时遇到了一些错误这里是 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;


@Override

protected 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) {


}


智慧大石
浏览 104回答 1
1回答

眼眸繁星

活动不需要实例化,因此只需要调用以下内容即可启动://check if user in nullif (firebaseUser != null){&nbsp; &nbsp; Intent intent = new Intent(MainActivity.this, Main2Activity.class);&nbsp; &nbsp; startActivity(intent);&nbsp; &nbsp; finish();}基本上你只需要删除这一行:new MainActivity(intent);并开始活动:startActivity(intent);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java