在Activity中直接new Intent()报错:NullPointerException
来源:互联网 发布:telent 端口 编辑:程序博客网 时间:2024/06/05 15:37
public class MainActivity extends AppCompatActivity { public static final String TAG = "MainActivity"; private Intent mIntent; //下面注释掉的代码会报nullPoiterException,因为MainActivity对象被创建时,就会调用new Intent(this,SecondActivity.class) //而new Intent()中,需要用到该MainActivity对象所attach的ContextImpl对象,该MainActivity对象所attach的ContextImpl对象是在 //MainActivity对象被创建后才会被MainActivity对象所attach()【在ActivityThread.java中的performLaunchActivity()中被attach】 //解决方法:1.在onCreate()中调用mIntent = new Intent(this,SecondActivity.class);因为onCreate()方法在attach()后面才会被调用。 *//private Intent mIntent= new Intent(this,SecondActivity.class);* @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mIntent = new Intent(this,SecondActivity.class); }}
阅读全文
0 0
- 在Activity中直接new Intent()报错:NullPointerException
- [其它]在eclipse中运行Junit报错NullPointerException
- bt.setOnClickListener(new OnClickListener()报错java.lang.nullpointerException
- 为什么在子线程中直接new Handler会报错?
- 关于intent.getParcelableArrayListExtra()报NullPointerException总结
- 利用Intent在Activity中传递数据
- .setOnClickListener报错NullPointerException
- dbvisualizer报错,NullPointerException
- springMVC报错NullPointerException
- controller中dao报nullPointerException
- 关于Popupwindow在Activity加载中显示报错问题
- Android开发中,调用removeView报NullpointerException错
- android面试03--通过startActivity(intent)调用Activity中的方法与new Activity调用Activity中方法的区别
- Activity 中 Intent 使用方法。
- android工程运行报错:unabel to stat activity componentinfo{xx.xx.xxActivity}java.lang.NullPointerException
- 如何在子线程中直接new Handler
- 【intent extra】Android Activity直接传递数据
- 导出EXCEL报错:NullPointerException
- 安卓高德地图API根据城市名获取对应的经纬度和地理编码
- centos 6.5的中文切换为英文!
- NDK学习之增量更新--合并APK
- FAFU OJ 依旧水水的dp3
- 消息队列设计精要
- 在Activity中直接new Intent()报错:NullPointerException
- ubuntu 16.04 安装umbrello
- windows安装solr
- x264输出统计值含义
- python的赋值和赋址
- Android RecyclerView:设置指定位置的两种方法
- 性能测试指标
- Android 屏幕适配之dimens(上线项目中实际应用)
- 出错的地方