清理项目,我的R.java文件赢得';由于XML文件中的错误而无法生成?
我试图在我的Genymotion emulator中运行我的项目,但是当我运行Android应用程序时,我添加的新更新按钮都没有显示出来。因此,我制作了一个项目的副本来运行“清理”,因为我的R.java文件在清理后没有生成,我是对的,因为在复制的项目中没有生成R.java文件。我几乎可以肯定这是我的XML文件中的一个问题,但是我的XML文件没有显示任何错误 我以前也犯过同样的错误,我在这里发布过: 没有生成R文件,因此MainActivity中的所有调用,如清理项目,我的R.java文件赢得';由于XML文件中的错误而无法生成?,java,android,xml,genymotion,Java,Android,Xml,Genymotion,我试图在我的Genymotion emulator中运行我的项目,但是当我运行Android应用程序时,我添加的新更新按钮都没有显示出来。因此,我制作了一个项目的副本来运行“清理”,因为我的R.java文件在清理后没有生成,我是对的,因为在复制的项目中没有生成R.java文件。我几乎可以肯定这是我的XML文件中的一个问题,但是我的XML文件没有显示任何错误 我以前也犯过同样的错误,我在这里发布过: 没有生成R文件,因此MainActivity中的所有调用,如mBitmap=BitmapFacto
mBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.crayon)代码>声明“R不能解析为变量”,我知道这表明XML文件中存在问题
这是我的activity_main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal|fill_horizontal|center"
android:orientation="horizontal" >
<RadioGroup
android:id="@+id/greyorcolor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/reyscale" />
<RadioButton
android:id="@+id/color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/color" />
</RadioGroup>
<RadioGroup
android:id="@+id/smallorlarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/large" />
<RadioButton
android:id="@+id/small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@string/small" />
</RadioGroup>
</LinearLayout>
<edu.berkeley.cs160.opalkale.prog2.DrawingView
android:id="@+id/drawing"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="3dp"
android:layout_weight="1"
android:orientation="vertical"
android:src="@drawable/ic_launcher" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Drawing</string>
<string name="greyscale">Greyscale</string>
<string name="color">Color</string>
<string name="small">Small Brush</string>
<string name="large">Large Brush</string>
<string name="hello_world">Hello world!</string> </resources>
问题窗口:
在此处输入代码这是因为eclipse无法构建项目。尝试重新启动eclipse,看看是否创建了R文件。如果没有,请立即再次清洁,看看是否有效。radiobutton的名称中有一个特殊字符@
<RadioButton
android:id="@+id/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@Greyscale" /> // Here
//这里
您需要删除我身上多次出现的@
,这就是我使用Android studio的原因
<RadioButton
android:id="@+id/grey"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="@Greyscale" /> // Here
让我们来看主要答案:)
首先,再次干净地保存项目,如果仍然没有生成R.java
文件,则重新启动。我希望这能奏效:)
这是我发布时的问题。:)
有两种可能的错误:
1:
您忘了在drawable文件夹中添加名为“crayon”的drawable
2:
包错误
:您只需要检查导入语句。
应该是这样的
导入com.test.example.R
您的包名=com.test.example我不太清楚这一点,但您使用的是eclipse吗?如果是的话,我也遇到过类似的问题,没有生成R.java,但是eclipse没有标记任何错误。在所有情况下,XML布局文件中实际上都存在错误,但为了检测它们,我必须打开“Problems”视图来找出它们是什么。如果您还没有打开它,您可以尝试这样做:窗口->显示视图->问题
我可以knw edu.berkeley.cs160.opalkale.prog2.DrawingView是否正确位于程序包中的哪一行出现错误?字符串资源文件是否以
标记结尾?此外,它不能阻止但需要时间缩进布局文件(在eclipse CTRL+A CTRL+I中),结构不清楚。@DigveshPatel是,因为它在xml文件中没有任何内容时工作,不工作时不要复制项目。清理日志,清理eclipse中的错误,然后清理项目,了解错误,修复错误并重新运行。请参阅类似的问题。eclipse没有问题,问题肯定出在我的XML文件中。我多次尝试重新启动、清理等,但没有任何改变。OP更新了他的问题。他已经修复了这个“打字错误”,但问题仍然没有解决。@Mehul这是一个无效的编辑。不要再这样做了。@MehulJoisar编辑时,您不能在现有帖子中添加任何内容。@user3301551:我试图改进您的答案,以便您能够学会回答。无论如何,对否决票感到满意。我不介意:-)@MehulJoisar我很欣赏您的工作,但按照规则,编辑仍然无效。如果我的答案是错误的,我不在乎反对票。我已经尝试过多次重启、清理等,但没有任何改变。这肯定是我的XML文件中的一个问题,CRAYON是一个可绘制的jpg(只是仔细检查一下。我应该在哪里查找import语句以查看它是否在那里?在我的自定义视图类中还是在我的主活动中?@Opal:在你的主活动中,我更新了以显示我的MainActivity.java文件。如果一开始没有生成R.java文件,则导入它不是问题是的,我在这里查看我以前的帖子,我添加了我的“问题”的图片,我也刚刚发布了我在上面的问题日志中看到的内容!