P
P
PeJlToFaN2021-06-22 13:01:07
Java
PeJlToFaN, 2021-06-22 13:01:07

I don’t understand what the error is, MainActivity and SecondActivity don’t start?

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 22180
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: java.lang. NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.Button.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3308)
at android.app.ActivityThread .handleLaunchActivity(ActivityThread.java:3457)
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:2044)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7562)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal. os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.widget.Button.findViewById(int)' on a null object reference
at com.example.myapplication.MainActivity.onCreate(MainActivity.java :18)
at android.app.Activity.performCreate(Activity.java:7893)
at android.app.Activity.performCreate(Activity.java:7880)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android .app.ActivityThread.performLaunchActivity(ActivityThread.java:3283)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-06-22
@zagayevskiy

Attempt to invoke virtual method 'android.view.View android.widget.Button.findViewById(int)' on a null object reference

because
setContentView(R.layout.activity_one_more);
l1.findViewById(R.id.level1);

Nobody fills l1, but you call a method on it.
need so l1 = findViewById(R.id.level1)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question