您的位置:首页 > 移动开发 > Android开发

android学习笔记

2010-12-10 18:36 148 查看
1、在activity 的 onCreate()方法,主要用于为创建一个activity完成初始化工作,其中

tools_text = (TextView) findViewById(R.id.TextView01);
tools_button =(Button) findViewById(R.id.Tools_ok);
tools_radiogroup = (RadioGroup) findViewById(R.id.RadioGroup01);
setContentView(R.layout.tools);

将导致tools_text等抛出空指针异常

super.onCreate(stateInstanceState);
setContentView(R.layout.tools);
tools_text = (TextView) findViewById(R.id.TextView01);
tools_button =(Button) findViewById(R.id.Tools_ok);
tools_radiogroup = (RadioGroup) findViewById(R.id.RadioGroup01);

是正确的写法

小结:空指针异常通常与函数的调用顺序有关,注意检查。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: