سؤال

I have an app supporting from hdpi to ldpi. It works fine, without any problem for accessing resources. In this app, I have a ListView, and I decided to add an image in each view of the list. So I prepared three png images, one for each resolution, and placed them in their respective resource directories.

All is fine with a hdpi 2.2 emulator, but it crashes with a NullPointerException in 2.2 mdpi and ldpi at the bindView method line where I put the drawable in the iImageView: mImageView.setImageDrawable(getBaseContext().getResources().getDrawable(R.drawable.hello) I've tried to replace getBaseContext() by getApplicationContext() or even removing it without success.

I guess that the app doesn't look in the -mdpi folder. However, I don't understand why the hdpi version works fine. Note that there is nothing in the bare drawable directory. Furthermore, the app knows how to look in these folders since it does it in a previous activity used to launch the one with the ListView.

Any Idea ?

هل كانت مفيدة؟

المحلول

Perhaps you should replace getBaseContext() with your context. See top answer in this question

نصائح أخرى

What is your target SDK? It should be > 3 (>1.5)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top