为什么当我创建一个新活动时,“setContentView”无法识别我的布局?

时间:2014-02-27 21:29:32

标签: java android r.java-file

我刚创建了一个新活动(project-> new-> android活动),我得到一个错误,其中R文件无法识别活动创建的布局。我使用 Ubuntu 13.10(64位)

public class OrderKaraokeActivity extends SherlockActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_karaoke);
    }
}

activity_order_karaoke:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".OrderKaraokeActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

enter image description here

控制台: 描述资源路径位置类型 activity_order_karaoke无法解析或者不是字段OrderKaraokeActivity.java / src / com / example / adicionalesprueba第18行Java问题

导入:

enter image description here

控制台问题:

enter image description here

2 个答案:

答案 0 :(得分:7)

删除以下

import com.twable.R;
import com.twable.R.layout;
import com.twable.R.menu;

并加入import com.example.adicionalesprueba.R

<强> ----

检查您的包浏览器(eclipse的左侧窗格),打开项目的gen文件夹,打开项目包,您应该看到R.java文件。如果不这样做,则表示您没有生成R文件。尝试清理项目Project --> Clean。如果文件仍然不存在,那么您的R文件尚未构建。这可能由于许多原因而发生。一个非常常见的问题是您的某个XML文件没有正确构建

enter image description here

答案 1 :(得分:1)

检查您的进口商品。如果它在那里生成,请删除导入android.R