【问题标题】:New xml layout file is not being added to R.java新的 xml 布局文件未添加到 R.java
【发布时间】:2016-04-21 04:37:42
【问题描述】:
<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:background="@drawable/background1"
            tools:context="com.example.flavours.Category" >

        <ImageView
                android:id="@+id/homeimage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_centerInParent="true"
                 android:src="@drawable/ice1"/>

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="25dp"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>

每次将构建目标 (6.0) 更改为 (5.0.1) 后,我都没有生成 R (R.id/layout) 的问题。 我已经多次清理项目,当我立即清理项目时,“r”出现错误(R 无法解析为变量)。我还导入了我的(com.example.flavours.R;)但它删除了我按 Ctrl+shift+o。

【问题讨论】:

  • 检查 res 文件夹中的所有内容,例如(可绘制、值和布局)等。
  • 我只有在我的项目中出现阻止生成 R.java 的错误时才会遇到这种情况;通常是 aapt 工具报告的错误。这可能是 res/ 目录中的无效 XML 或文件名或其他错误。检查 aapt 的输出以查看错误是什么。

标签: android eclipse r.java-file


【解决方案1】:

我检查了您的代码并对其进行了测试, 真实有效!

确保您的新 .xml 文件具有有效名称
有效名称仅包含

  1. 小写字母`a-z`
  2. 数字“0-9”,它们不应位于文件名的第一个。
  3. 下划线`_`

也可以右键单击项目并清理源代码

Right Click On Project > Source > Clean Up...

或检查构建路径是否有不需要的更改

Right Click On Project > Build Path > Configure Build Path...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多