Android Studio在意外梯度同步后找不到R.java
在Android Studio中工作时,我无意中点击了工具栏上的“与Gradle文件同步项目”按钮。现在,R的所有实例都以红色突出显示为“无法解析符号R”。此外,除目录结构工具栏中的应用程序名称外,所有文件夹都带有红色下划线,我收到一条消息,说在我的一个XML布局文件中找不到三个选中单选按钮的ID(即使它们在下面几行)。项目结构中甚至没有R.java。重新启动Android Studio并没有解决这个问题;也没有再按同一个按钮 编辑:我希望能够将我所有的文件复制到一个新项目中,但这个问题在新项目中也依然存在 这是我的XML文件;我已删除默认选中的按钮:Android Studio在意外梯度同步后找不到R.java,java,android,r.java-file,Java,Android,R.java File,在Android Studio中工作时,我无意中点击了工具栏上的“与Gradle文件同步项目”按钮。现在,R的所有实例都以红色突出显示为“无法解析符号R”。此外,除目录结构工具栏中的应用程序名称外,所有文件夹都带有红色下划线,我收到一条消息,说在我的一个XML布局文件中找不到三个选中单选按钮的ID(即使它们在下面几行)。项目结构中甚至没有R.java。重新启动Android Studio并没有解决这个问题;也没有再按同一个按钮 编辑:我希望能够将我所有的文件复制到一个新项目中,但这个问题在新项目
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:screenOrientation="landscape"
tools:context="com.cmpt276.darren.minions.OptionsMenu">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:id="@+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/num_rows"
android:id="@+id/textView8"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--//android:checkedButton="@id/rows3"-->
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rows3"
android:id="@+id/rows3" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rows4"
android:id="@+id/rows4" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rows8"
android:id="@+id/rows8" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/num_minions"
android:id="@+id/textView9" />
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--android:checkedButton="@id/numMinions6"-->
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minions_6"
android:id="@+id/numMinions6" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minions_10"
android:id="@+id/numMinions10" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minions_15"
android:id="@+id/numMinions15" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minions_20"
android:id="@+id/numMinions20" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/num_columns"
android:id="@+id/textView10"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/num_columns">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/columns4"
android:id="@+id/columns4" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/columns6"
android:id="@+id/columns8" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/columns12"
android:id="@+id/columns12" />
</RadioGroup>
</LinearLayout>
</RelativeLayout>
请参阅
XML问题将阻止R文件的生成。因此,在代码中使用comb
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checkedButton="@id/rows3"// error line
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rows3"
android:id="@+id/rows3" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rows4"
android:id="@+id/rows4" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rows8"
android:id="@+id/rows8" />
</RadioGroup>
这应该是可行的。或者请以编程方式定义它。这样可以避免任何此类问题。已经在这里回答了这个问题:
答案的一部分:
清理并生成如何?文件->使缓存无效并重新启动可能会解决问题。如果我的一个布局文件无法编译,我经常会在R周围看到一些奇怪的事情。@IllegalArgument这只会让事情变得更糟。现在,我的布局呈现为纯灰色背景上的微小黑色文本。显然有57个样式错误。@我想nexus手机周围的布局已经不见了。如果没有错误,请尝试编译并运行代码。我有时会看到这种行为,但它并没有阻止我编译。是否还有其他错误?
android:checkedButton="@+id/rows3"//