java.lang.NullPointerException:TextView.setText(java.lang.CharSequence)' on a null object reference
来源:互联网 发布:淘宝客服语气词的使用 编辑:程序博客网 时间:2024/05/21 15:05
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.phonesafe, PID: 12501 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
bug分析
问题出在 作用在一个空的对象引用上 ,那么锁定在
- setText方法的参数为空
- TextView 为空
bug 解决
- 打印 setText方法的参数
- 打印TextView
看那个为空,找对应原因,看是哪块写错,或者遗漏了什么
最后切记
调试bug ,最忌讳想当然,异想天开,不要认为自己拿手的就是完全正确的。
最直接有效的方法:在每个流程关键处,打印语句,看是否走到这;打印每个对象,看是否为空,是否有值。
多线程时,一定要在每个线程处都打印,追溯对象每一处状态。
不要懒于写Log,否则就是自己在浪费自己的时间。
0 0
- java.lang.NullPointerException:TextView.setText(java.lang.CharSequence)' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
- 安卓setText(java.lang.CharSequence) on a null object reference解决办法
- java.lang.NullPointerException:Attempt to invoke virtual method xxx on a null object reference
- Invoke interface method 'java.lang.Object[]java.util.Collection.toArray()'on a null object reference
- caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void … on a null object
- Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
- Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference(Fb)
- Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object
- ddms:null java.lang.NullPointerException
- Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null obj
- Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null
- NullPointerException: with ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
- java.lang.CharSequence翻译
- Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null objec
- 解决Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null···
- POJ3264_Balanced Lineup_线段树维护最大值和最小值
- hadoop集群故障排除(定期更新)
- (51nod)1012
- Linux学习笔记之RedHat Enterprise Linux 6.4 使用 Centos 6 的yum源问题
- jQuery--1省市选择
- java.lang.NullPointerException:TextView.setText(java.lang.CharSequence)' on a null object reference
- L1-005. 考试座位号
- could not get a field value by reflection getter of
- Java 接收 URL文件流 保存本地 DEMO
- MATLAB作业
- 高效编写微信小程序
- margin、padding的属性值
- iOS基础——屏幕适配之autoResizing、autoLayout、sizeClass
- 轻舟已过万重山——真正的技术派公司是怎么联调、测试和发布的?