0

I'm trying to set an image from a non Activity class, the drawable name is saved in a string and comes from another methor but the problem is that getPackageName() gives me this error: "cannot resolve method 'getPackageName()'" and I have no idea what to do, here is my code:

String[] string = printArray(false, context);

image1.getResources().getIdentifier(string[0] , "drawable", getPackageName());
image2.getResources().getIdentifier(string[1] , "drawable", getPackageName());
image3.getResources().getIdentifier(string[2] , "drawable", getPackageName());
3
  • where does the drawable located? Commented Jun 18, 2014 at 20:37
  • @Rod_Algonquin at res/drawable-hdpi Commented Jun 18, 2014 at 20:38
  • can you post the whole class of the non activity Commented Jun 18, 2014 at 20:40

1 Answer 1

1

try image1.getContext().getPackageName()

Sign up to request clarification or add additional context in comments.

5 Comments

That worked because it doesn't give an error but, it doesn't work when i try to do this: image1.setImageResource( image1.getResources().getIdentifier(string[0] , "drawable", image1.getContext().getPackageName()));
what is inside string[0] ?
The name of the image without the extension ofc
can you check that the result of image1.getResources().getIdentifier... returns something other than 0?
@user3272243 what fixed the issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.