0

I can not understand what is the error that I have, what I did wrong? I have followed the various tutorials on the internet for how to set up an image from drawable, because it does not work?

Drawable drawable = mContext.getResources().getDrawable(
                mContext.getResources().getIdentifier(
                        sampleItem.get(position).getImage(), "drawable",
                        mContext.getPackageName()));

        image.setImageDrawable(drawable);

Logcat:

   W/ResourceType(29255): No package identifier when getting value for resource number 0x00000000
D/AndroidRuntime(29255): Shutting down VM
W/dalvikvm(29255): threadid=1: thread exiting with uncaught exception (group=0x4331c1a0)
E/AndroidRuntime(29255): FATAL EXCEPTION: main
E/AndroidRuntime(29255): Process: com.treffedin.navigationdrawerdemo, PID: 29255
E/AndroidRuntime(29255): android.content.res.Resources$NotFoundException: Resource ID 
Nick Pass
  • 80
  • 8
  • 1
    What does `sampleItem.get(position).getImage()` return? It should return the string name of the resource you want. – Ken Wolf Nov 07 '14 at 14:34

2 Answers2

0

Try cleaning and building the project.

Android is searching the image with id resource 0x00000001, which is not correct.

If that doesn't works try deleting the "gen" folder and building again.

Good luck :)

Ashish Tamrakar
  • 810
  • 10
  • 24
0

I solved,

changed

sampleItem.setImage ("image_0.png"); 

to

sampleItem.setImage ("image_0");

beginner's mistake.

Nick Pass
  • 80
  • 8