简体   繁体   中英

Why when I create a new activity, “setContentView” not recognize my layout?

I just created a new activity (project-> new-> android activity) and I get an error where the R file, which does not recognize the layout created by the activity. I use Ubuntu 13.10 (64 bits)

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>

在此处输入图片说明

Console:

Description Resource    Path    Location    Type
activity_order_karaoke cannot be resolved or is not a field OrderKaraokeActivity.java   /src/com/example/adicionalesprueba  line 18 Java Problem

Import:

在此处输入图片说明

Console problem:

在此处输入图片说明

remove the following

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

and include import com.example.adicionalesprueba.R

----

Check your package explorer (the left pane of eclipse), open the gen folder of your project, open the package of your project, You should see a R.java file. If you do not, you're R file is not being generated. Try to clean your project, Project --> Clean . If the file is still not there, then you're R file is not being built. This can happen for many reasons. A very common one is that one of your XML files is not properly structured

在此处输入图片说明

Check your imports. Remove import android.R if it's generated there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM