android.content.res.Resources$NotFoundException: Resource ID #0x7f07007e

╄→гoц情女王★ 提交于 2019-12-18 08:09:39

问题


I am Trying to implement like feature in the app, here is the snippet from the Viewholder in the recycled view.

Recycler customadapter

public class PostAdapterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

TextView title,user,description,tag,time,designation;
Long date;
ImageView imageView,bookmark,profilepic,sharebutton,like;
RelativeLayout head;
LinearLayout content;
DatabaseReference reference;
Context context;
String name;

public void setContext(Context context) {
    this.context = context;
}

public PostAdapterViewHolder (final View itemView) {
    super(itemView);
    itemView.setOnClickListener(this);
    head = (RelativeLayout) itemView.findViewById(R.id.head);
    content = (LinearLayout) itemView.findViewById(R.id.content);
    imageView =(ImageView)itemView.findViewById(R.id.imageview);
    designation = (TextView) itemView.findViewById(R.id.designation);
    like =(ImageView)itemView.findViewById(R.id.like);
    profilepic = (ImageView) itemView.findViewById(R.id.imageView2);
    bookmark =(ImageView)itemView.findViewById(R.id.bookmark);
    title = (TextView) itemView.findViewById(R.id.title);
    description = (TextView) itemView.findViewById(R.id.description);
    time = (TextView) itemView.findViewById(R.id.date);
    tag = (TextView) itemView.findViewById(R.id.tag);
    sharebutton = (ImageView) itemView.findViewById(R.id.sharebutton);
    user = (TextView) itemView.findViewById(R.id.username);

    like.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ImageView i = (ImageView) itemView.findViewById(R.id.like);
            Drawable a = i.getBackground();

            if (a.getConstantState().equals(context.getDrawable(R.drawable.emptyup).getConstantState())){

                i.setImageDrawable(context.getDrawable(R.drawable.fillup));

            } else {

                i.setImageDrawable(context.getDrawable(R.drawable.emptyup));

            }

        }
    });

  }
} 

}

01-09 10:43:45.747 6602-6602/ctize.connectplus.com.communitize E/AndroidRuntime: FATAL EXCEPTION: main Process: ctize.connectplus.com.communitize, PID: 6602 android.content.res.Resources$NotFoundException: Resource ID #0x7f07007e at android.content.res.Resources.getValue(Resources.java:1397) at android.content.res.Resources.getDrawable(Resources.java:843) at android.content.Context.getDrawable(Context.java:458) at ctize.connectplus.com.communitize.PostAdapterViewHolder$2.onClick(PostAdapterViewHolder.java:98) at android.view.View.performClick(View.java:5226) at android.view.View$PerformClick.run(View.java:21350) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5582) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)


回答1:


Your app crash when the activity concerned should be displayed ?

Check if in you activity you have a drawable v24 like this

Then, if yes, change the display of your files from Android to Project at the very top of the hierarchy of your files : From

to

And drag and drop the drawable in the directory drawable v-24 to the directory drawable.

That's all. Try if it's ok




回答2:


By seeing the logs. The problem is in your drawable background take a look at it. You have type X24 image change it and it will fix your problem.

Second thing is you are seeing two images at a time. So you need to remove the background that you are setting in your .xml file and you are good to go.




回答3:


You are using context.getDrawable(R.drawable.fillup) which will only work in versions higher than LOLLIPOP. Use context.getResources().getDrawable(R.drawable.fillup) to get the images from resource.




回答4:


<CheckBox android:layout_width="wrap_content"
 android:layout_height="wrap_content" 
 android:text="new checkbox"
 android:background="@drawable/checkbox_background" 
 android:button="@drawable/checkbox" />

Try to use checkbox instead of ImageView

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_checked="true" android:state_focused="true"
  android:drawable="@drawable/fillup" />
 <item android:state_checked="false" android:state_focused="true"
  android:drawable="@drawable/emptyup" />
 <item android:state_checked="false"
  android:drawable="@drawable/emptyup" />
 <item android:state_checked="true"
  android:drawable="@drawable/fillup" />
</selector>

if (a.getConstantState().equals(context.getDrawable(R.drawable.emptyup).getConstantState())){

            i.setImageDrawable(context.getDrawable(R.drawable.fillup));

        } else {

            i.setImageDrawable(context.getDrawable(R.drawable.emptyup));

        }

These lines are giving you error because of your android version issue.




回答5:


Follow this https://developer.android.com/guide/topics/graphics/vector-drawable-resources.html#vector-drawables-backward-solution, You should use setImageResource() instead of setImageDrawable()




回答6:


Check if the drawable resource image is in drawable folder, not drawable-24.
I already have this problem but solve it by moving the image resource to drawable folder.




回答7:


Please try a clean build, may be the R file is wrong



来源:https://stackoverflow.com/questions/48161713/android-content-res-resourcesnotfoundexception-resource-id-0x7f07007e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!