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

0 like 0 dislike
4.5k views
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)
by | 4.5k views

1 Answer

0 like 0 dislike
Best answer
Your TextView name_home not found in the file layout. He was assigned a null, here is oshibka. Check that the file layout activity_home.xml there is a TextView and assigned id as "@+id/name_home"
by
selected by

Related questions

110,608 questions
257,187 answers
0 comments
40,796 users