解决方案 »
- 新手遇到问题,求教!
- android地图应用如何获取周边商家信息?
- 修改Spinner的Dialog的疑问。谢谢指导
- 请教大家关于Adapter重写的问题
- 关闭uboot MMU 会导致android2.3 S5pv210 系统不稳定?!why
- 连接FTP时空指针。。。
- InstrumentationTestCase等做测试的那些类能不能在普通程序里用啊?
- creat new android virtual device 数值填完之后,点击ok无任何反应,这几天一直没有解决办法,希望高人指点
- Android ListView问题,求解
- 我用Process调用安卓自带的Ping时出现错误
- 图片部分区域的填充问题,想了好久了
- android gps gettime 一直返回-2881000?求教原因
mButton=(Button)findViewById(R.id.mButton);
mButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//do something
}
});
此时就会因为findViewById并没有找到正确的资源,导致mButton=null,setOnClickListener会引发NullException.
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton=(Button)findViewById(R.id.mButton);
}setContentView会把xml资源绑定到Activity上,此后才能直接做find操作,否则一定是空的
感谢指点.NULL的问题解决了,的却是这样.但是,IDEA里边的R文件的内容始终为空是什么情况?如下:
/*___Generated_by_IDEA___*/package com.example.App;/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}
在eclipse中,R文件里面会有好几个静态类.比如id,attr什么的.这里虽然没有,但是也不会报错,程序同样运行正常.请指点