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);
是正确的写法
小结:空指针异常通常与函数的调用顺序有关,注意检查。
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);
是正确的写法
小结:空指针异常通常与函数的调用顺序有关,注意检查。
相关文章推荐
- Android学习笔记——关于onConfigurationChanged
- Android学习笔记(一)
- Android学习笔记之Menu的ShowAsAction属性的设置
- Android学习笔记(三)
- Android学习笔记 - Spinner
- Android学习笔记 - Service
- Android学习笔记(四十):Preference的使用
- Java4Android学习笔记
- Android学习笔记 day05 _ 网络编程2
- Android学习笔记
- Pro Android学习笔记:调试和分析(3):adb命令、模拟器控制台和StrictMode
- Android学习笔记(一): Fragment(一) 基本概念和生命周期
- Android学习笔记(三七):再谈屏幕切换
- Android学习笔记(五二):服务Service(中)- 继承Service类
- Android学习笔记--解析json
- Android学习笔记之高仿微信界面实现
- Android学习笔记(12)————利用SQLiteOpenHelper来管理SQLite数据库 .
- Android学习笔记之Handler内存泄露
- Android学习笔记——关于onConfigurationChanged
- Android学习笔记—第三章 Intent 意图