Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resources$NotFoundException: Resource ID #0x7f040015

Tags:

java

android

I am inflating R.id.itemView in order to add it to a gridLayout:

View item = getLayoutInflater().inflate(R.id.itemView,null);

However, I am getting this error when inflating it:

Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f040015 type #0x12 is not valid

That resource number corresponds to itemView (I checked it on R.java). Here is the file where itemView is located (color_view.xml in res/layout):

<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>

I tried cleaning,building and deleting R.java but it doesnt solve the problem. What is the cause of this problem?

like image 655
Pedro S Avatar asked Jan 23 '26 07:01

Pedro S


1 Answers

You can't supply an id to the first argument of inflate, that can only be a layout. You can only inflate a layout like this:

View item = getLayoutInflater().inflate(R.layout.color_view,null);
like image 136
Feng Dai Avatar answered Jan 25 '26 22:01

Feng Dai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!