-1

The function called to switch activity is

public void GoToLogIn(View v){
    Intent goToLogIn = new Intent(MainActivity.this,LogInActivity.class);
    startActivity(goToLogIn);
    finish();
}

This segment of code is showing error on logcat:

2021-08-21 12:43:33.396 9644-9644/com.example.expenditurehandlingapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.expenditurehandlingapplication, PID: 9644
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.expenditurehandlingapplication/com.example.expenditurehandlingapplication.LogInActivity}: 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:2679)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
    at android.app.ActivityThread.-wrap11(Unknown Source:0)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    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 'android.content.pm.ApplicationInfo android.content.Context.getApplicationInfo()' on a null object reference
    at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:152)
    at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:157)
    at android.content.Context.obtainStyledAttributes(Context.java:655)
    at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:842)
    at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809)
    at androidx.appcompat.app.AppCompatDelegateImpl.findViewById(AppCompatDelegateImpl.java:633)
    at androidx.appcompat.app.AppCompatActivity.findViewById(AppCompatActivity.java:259)
    at com.example.expenditurehandlingapplication.LogInActivity.<init>(LogInActivity.java:10)
    at java.lang.Class.newInstance(Native Method)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1174)

I have given the proper class name, but the app still stops working at this point. Can anyone please tell me what did i do wrong in this?

  • 1
    I don't think the problem is with this Intent code. The problem may be in `LogInActivity`. Can you show the code of `LoginInActivity` and xml of `LoginInActivity`? – Dương Minh Aug 21 '21 at 07:59
  • We can't tell you what you did wrong or how to fix it because the problem is not occurring in the code snippet that you showed us. However, the duplink explains how >you< can examine the (complete) evidence starting from the stack trace and work it out for yourself. – Stephen C Aug 21 '21 at 08:15

1 Answers1

0

Are you sure that you added all activities to Manifest file?