开发者

Problem with some mdpi and ldpi ressources with android

开发者 https://www.devze.com 2023-02-05 14:23 出处:网络
I have an app supporting from hdpi to ldpi. It works fine, without any problem for accessing resources.

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号