D
D
Dimka123r2018-06-04 02:41:10
Java
Dimka123r, 2018-06-04 02:41:10

What does the error "NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)'" mean?

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        name_home = (TextView) findViewById(R.id.name_home);
        name_home.setText("abc");

06-03 23:31:03.847 25033-25033/dmitribak.clienttaxi.clienttaxi E/AndroidRuntime: FATAL EXCEPTION: main
Process: dmitribak.clienttaxi.clienttaxi, PID: 25033
java.lang.RuntimeException: Unable to start activity ComponentInfo{dmitribak. clienttaxi.clienttaxi/dmitribak.clienttaxi.clienttaxi.HomeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at android.app .ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android. app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com. android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at dmitribak.clienttaxi.clienttaxi.HomeActivity.onCreate(HomeActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2018-06-04
@vasilek-nik

Your TextView name_home was not found in the markup file. It was assigned null, that's the error. Check that there is a TextView in the activity_home.xml markup file and its id is assigned as "@+id/name_home"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question