[英]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.我刚刚创建了一个新活动(项目-> 新活动-> android 活动),我收到一个错误,其中 R 文件无法识别该活动创建的布局。 I use Ubuntu 13.10 (64 bits)我使用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: 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
并包括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.检查您的包资源管理器(eclipse 的左侧窗格),打开项目的gen
文件夹,打开项目的包,您应该看到一个R.java
文件。 If you do not, you're R file is not being generated.如果不这样做,则不会生成 R 文件。 Try to clean your project, Project --> Clean
.尝试清理您的项目, Project --> Clean
。 If the file is still not there, then you're R
file is not being built.如果该文件仍然不存在,那么您没有构建R
文件。 This can happen for many reasons.发生这种情况的原因有很多。 A very common one is that one of your XML files is not properly structured一个很常见的问题是您的一个 XML 文件的结构不正确
Check your imports.检查您的进口。 Remove import android.R if it's generated there.如果它在那里生成,则删除导入 android.R 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.