安卓setText(java.lang.CharSequence) on a null object reference解决办法
来源:互联网 发布:getdata软件 编辑:程序博客网 时间:2024/06/05 06:38
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
故障出现的现象:
在一个Fragment的前面声明了全局变量
private TextView textViewTodayTemp;
在onActivityCreated()
却又声明了局部变量并关联:
TextView textViewTodayTemp = ( TextView)getActivity().findViewById(R.id.textViewTodayTemp);
然后在别的方法中调用:
textViewTodayTemp.setText()
导致出现错误:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
故障解决办法:
onActivityCreated()中,不用声明局部变量,去掉前面的TextView,改为:
textViewTodayTemp = ( TextView)getActivity().findViewById(R.id.textViewTodayTemp);
这样故障解决。
- 安卓setText(java.lang.CharSequence) on a null object reference解决办法
- 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
- Invoke interface method 'java.lang.Object[]java.util.Collection.toArray()'on a null object reference
- Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
- java.lang.NullPointerException:Attempt to invoke virtual method xxx on a null object reference
- on a null object reference 问题的解决办法
- Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference(Fb)
- "on a null object reference"问题解决方案
- on a null object reference 错误
- 安卓开发——报错:Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null
- Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object
- 关于PinnedHeaderExpandableListView使用的时候on a null object reference
- android.content.Context.getContentResolver()' on a null object reference错误
- NullPointerException: with ActionBar.setDisplayHomeAsUpEnabled(boolean)' on a null object reference
- monkey: android viewpager.offset on a null object reference
- js基础之各种基本类型及引用类型的转换之开篇
- [leetcode] 718. Maximum Length of Repeated Subarray
- UE4移动组件详解(二)——移动同步机制
- Merge Two Binary Trees
- MAC 下个人常用命令备忘录
- 安卓setText(java.lang.CharSequence) on a null object reference解决办法
- 如何让eclipse进行智能提示
- 数据结构-用数组模拟栈
- not get much sleep that night after the
- TensorBoard-01-网络结构
- spring jar包详解
- 洛谷P3371 【模板】单源最短路径
- 基于mint-ui的移动应用开发案例一(简介)
- 爬虫简要示例 以简书四灵传奇为例