我正在膨胀R.id.itemView以便将其添加到一个gridLayout中:
View item = getLayoutInflater().inflate(R.id.itemView,null);
然而,当我尝试将其填充时,出现了以下错误:
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040015 type #0x12 is not valid
该资源编号对应于itemView(我在R.java中检查过)。 这是包含itemView的文件(在res/layout中的color_view.xml):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res/com.example.colors"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<View
android:id="@+id/itemView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="5dp"
android:background="@drawable/color_shape" />
</RelativeLayout>
我尝试清理、构建和删除 R.java 文件,但这并不能解决问题。那么这个问题的原因是什么?