Attempt to invoke virtual method 'void android.widget.TextView.setText错误

方兴旺
2023-12-01

整了接近一个小时的错误,有时候不能仅仅因为AS的报错就跟着报错语句zhao找原因,有时候可能因为随着一个Activity的增多,导致很多长得相似(比如userName,user_name,tv_userName,tv_user_name),此时你找到的id并不是对应界面所具有的id,也就是说是别的界面的id,自然你找不到这个东西,更别提给他赋值了。as的自动提示可能会导致你的误判,然后就是写程序的时候一定要认真。
 

11-22 15:11:46.932 1279-1279/dachen.mr.movingone.registerandlogin E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                    Process: dachen.mr.movingone.registerandlogin, PID: 1279
                                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{dachen.mr.movingone.registerandlogin/dachen.mr.movingone.registerandlogin.UserInfoActivity}: 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:2325)
                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
                                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:151)
                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                        at android.os.Looper.loop(Looper.java:135)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                        at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                                                                                     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
                                                                                        at dachen.mr.movingone.registerandlogin.UserInfoActivity.setValue(UserInfoActivity.java:77)
                                                                                        at dachen.mr.movingone.registerandlogin.UserInfoActivity.initData(UserInfoActivity.java:55)
                                                                                        at dachen.mr.movingone.registerandlogin.UserInfoActivity.onCreate(UserInfoActivity.java:41)
                                                                                        at android.app.Activity.performCreate(Activity.java:5990)
                                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
                                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
                                                                                        at android.app.ActivityThread.access$800(ActivityThread.java:151) 
                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                        at android.os.Looper.loop(Looper.java:135) 
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5254) 
                                                                                        at java.lang.reflect.Method.invoke(Native Method) 

 

 类似资料: