简体   繁体   English

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

[英]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.

相关问题 为什么当我开始一项新活动时我的背景消失了? - why does my background disappear when i start a new activity? 如何使由setContentView()设置的textview(具有透明背景)中的“文本”显示在activity.xml中的布局上方? - How do I make a “text” from textview(with a transparent background) set by setContentView( ) be displayed above my layout in activity.xml? Android 工作室 setContentView(R.layout.activity_login); 即使我的第二个活动名称 activity_login 在布局文件夹中存在,也无法正常工作 - Android studio setContentView(R.layout.activity_login); is not working even my second activity name activity_login is presenr in layout folder 错误 setContentView(R.layout.activity_main) - error setContentView(R.layout.activity_main) setContentView(R.layout.activity_main) 上的异常; - Exception on setContentView(R.layout.activity_main); setContentView(R.layout.activity_login)上的 InflateException; - InflateException on setContentView(R.layout.activity_login); 每当我尝试在模拟器中运行代码时,它都表明应用程序不断停止,并且错误地进入了setcontentview(R.layout.Main_activity) - whenever i'm trying to run my code in emulator it is showing apps keeps stopping and in error i'm getting in setcontentview(R.layout.Main_activity) 我应该何时创建新活动? - When should I create a new activity? 调用 setContentView(R.layout.activity_main); 时应用程序崩溃; 第二次 - App crashing when calling setContentView(R.layout.activity_main); for the second time 如何使用setContentView以编程方式创建admob横幅(new Activity(this));不使用xml? - How to create admob banner programatically with setContentView(new Activity(this)); without using xml?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM