I want to display data on the profile page stored in firebase, but when I try to display text with only numbers, and run the application and then go to the profile page for the user, it gives an error like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.drheartbeatmonitor, PID: 3415
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.drheartbeatmonitor/com.example.drheartbeatmonitor.Profile}:
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:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.drheartbeatmonitor.Profile.onCreate(Profile.java:67)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
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:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
This is my code : 1.login page:
String ID_Device = snapshot.child(Username).child("ID_Device").getValue().toString();
String HealthInsure = snapshot.child(Username).child("Health Insure").getValue().toString();
intent.putExtra("ID_Device", ID_Device);
intent.putExtra("Health Insure", HealthInsure);
2. profile page
String ID_Device = Patient.ID_Device;
String HealthInsure = Patient.HealthInsure;
health_insure.setText(HealthInsure);
ID_Dev.setText(ID_Device);
`Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.example.drheartbeatmonitor.Profile.onCreate(Profile.java:67)`
In Profile.java line 67 are you trying to setText() on a null object? This could mean that the TextView you are trying to set the text is not yet created. Make sure you have called setContentView() to set the layout and then retrieved the TextView object via findViewById() before calling setText().