这个问题在这里已经有答案了:
什么是nullpointerexception,如何修复它(12个答案)
上个月关门了。
我想在firebase中存储的配置文件页上显示数据,但当我尝试只显示数字文本,运行应用程序,然后转到用户的配置文件页时,会出现如下错误:
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)
这是我的代码:1.登录页面:
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.个人资料页
String ID_Device = Patient.ID_Device;
String HealthInsure = Patient.HealthInsure;
health_insure.setText(HealthInsure);
ID_Dev.setText(ID_Device);
1条答案
按热度按时间1rhkuytd1#
在profile.java第67行中,您是否正在尝试对空对象执行settext()?这可能意味着您试图设置文本的文本视图尚未创建。确保已调用setcontentview()来设置布局,然后在调用settext()之前通过findviewbyid()检索textview对象。