繁体   English   中英

错误 R.java

[英]Error in R.java

第二行这段代码R.java有错误

 public static final class id {
    public static final int 2ndQ=0x7f05000a;
    public static final int FirstQuestion=0x7f050000;
    public static final int MainTitle=0x7f050003;
    public static final int SecondQuestion=0x7f050008;
    public static final int btnstrt=0x7f050007;
    public static final int editText1=0x7f050001;
    public static final int imageView1=0x7f050006;
    public static final int maindescrip=0x7f050004;
    public static final int radio0=0x7f05000b;
    public static final int radio1=0x7f05000c;
    public static final int radio2=0x7f05000d;
    public static final int radioGroup1=0x7f050009;
    public static final int toq1=0x7f050005;
    public static final int toq2=0x7f050002;
    public static final int toq3=0x7f05000e;

它给了我这个错误

标记“2”的语法错误,删除该标记

我尝试删除该行,因为它是我不再拥有的 TextView 的 ID。 事实上,我将 TextView 的 ID 从“2ndQ”更改为“SecondQuestion”。

我如何摆脱错误? 它阻止我测试我的应用程序。

编辑:为了澄清这一点,id 根本不存在于我的项目中。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/SecondQuestion"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:text="@string/secondQ"
        android:layout_marginTop="30dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:textSize="25dp"
        android:textStyle="bold" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/2ndQ"
        android:layout_below="@+id/2ndQ"
        android:layout_marginTop="74dp" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="@string/q2Answer1" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/q2Answer2" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/q2Answer3" 
            android:gravity="center" />
    </RadioGroup>

    <Button
        android:id="@+id/toq3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:text="@string/buttonForQuestion3"
        android:textSize="20dp"
        android:clickable="false" />

</RelativeLayout>

我尝试删除该行,因为它是我不再拥有的 TextView 的 ID

听起来 R.java 文件还没有更新,请尝试从以下一些通用指南开始:

  • 不要手动编辑gen文件夹中的任何文件,因为这些文件是自动为您构建的。
  • 如果您发现它不同步,请尝试刷新项目。
  • 如果那不起作用,请尝试清理(项目 -> 清理)
  • 如果这不起作用,请从 Eclipse 中删除gen文件夹(不要惊慌),然后它将由 Eclipse 重建 - 但是,如果存在某种编码错误,它可能不会立即执行此操作。

从 Android 开发开始,我有一条非常相似的错误消息。 在我的例子中,这是一个 res 字符串上的简单命名错误 - 我有 android:id="@+id/edit/message"。 第二个 / 应该是下划线。

唯一的错误消息在 R.java 中,因此在开始开发时非常混乱。

5 小时后,我终于找到了这个地狱的底部,我也有这个错误,但上面提到的方法都没有帮助,显然我错误地重命名了属于 android internal: 的文件中的 id 不仅如此- 我重命名为 sth illegal (@+id/@+id/checkbox_spinner) 使用 notepad++ 搜索我找到文件在 c.\Users\.android\build-cache..,我删除了 build-cache 文件夹,下次启动AS 的速度自然较慢,因为它创建了所有必要的文件,而且 WOALLA! 问题解决了!

清理并构建您的应用程序,然后尝试再次运行您的应用程序。不要在其自动生成的 R.java 中执行任何操作。转到项目并清理它,构建它。然后尝试再次运行。

确保 xml 文件中的元素不为空。 当存在未使用或没有值的空元素时,R 文件不喜欢它。 例如:

第 1 行:平均身高

第 2 行:

当第 2 行具有空值时,R 文件不喜欢它。

我也有这个确切的问题。 在我的 R.id 中有一个错误说要删除令牌,但我无法删除它,因为它不再在我的 xml 中的任何地方定义。所以我有一个

public static final int 2ndQ=0x7f05000a;

在我的 R.java 中,即使我清理了我的项目,我也无法摆脱。

为了摆脱它,我不得不

  • 使用“2ndQ”这个错误 ID 重新创建一个 TextView
  • 清理项目并更新 R.java
  • 然后删除我刚刚创建的牺牲TextView

瞧,你的 R.java 应该是固定的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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