IntelliJ IDEA 13新建安卓工程之后打开R文件发现没有内容.
pedoc 2014-01-29 07:08:32 RT.
升级到IntelliJ IDEA 13之后,新建安卓工程,编译之后一切正常,也能够在虚拟机和真机上运行.但是,在main.xml里面定义了一个Button之后通过findViewById进行查找却没有找到Button导致null指针异常.然后定位到R.java发现这个文件的内容如下:
/*___Generated_by_IDEA___*/
package com.example.Test;
/* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
public final class R {
}
根本没有看到id.attr什么的定义.
mail.xml文件内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MyActivity"
android:id="@+id/mButton"
/>
</LinearLayout>
MyActivity.java内容如下:
public class MyActivity extends Activity
{
private Button mButton;
/* Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mButton=(Button)findViewById(R.id.mButton); //此处运行的时候,mButton会是null.
setContentView(R.layout.main);
}
}
奇怪的是:
(1)
R.id.mButton是可以的,但是Ctrl+B转到定义的时候却不是跳转到R.id.mButton=xxx那里.而是跳转到main.xml里面的android:id="@+id/mButton".
(2)
即使是这样,编译没有错误,也能在机器上运行.
请高手指点一下为什么?