0

I'm getting this error log from google and I don't know what's causing it. This resource is in the folder that it says that it's not. I have never ran into this error myself. Here's the error:

android.content.res.Resources$NotFoundException: File res/drawable-mdpi/notebook_ul.jpg from drawable resource ID #0x7f020090
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.Resources.getDrawable(Resources.java:581)
at android.view.View.setBackgroundResource(View.java:7391)
at com.bfreq.dice.fragments.SettingsFrag.onCreateView(SettingsFrag.java:76)
..............................
Caused by: java.lang.NullPointerException.........

Here's me calling the resource in my fragment

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        View v = inflater.inflate(R.layout.settings, container, false);

        // Initializing Background
        rLayout = (RelativeLayout) v.findViewById(R.id.relativeLayout_Settings);
        switch (background) {
        case 0:
            rLayout.setBackgroundResource(R.drawable.clay_ul);
            break;
        case 1:
            rLayout.setBackgroundResource(R.drawable.parchment_ul);
            break;
        case 2:
            rLayout.setBackgroundResource(R.drawable.brownpaper_ul);
            break;
        case 3:
            rLayout.setBackgroundResource(R.drawable.notebook_ul);
            break;
        case 4:
            rLayout.setBackgroundColor(Color.WHITE);
            break;
        }
            ........
            return v;
        }

I Also call it from a method. Now I know that I'm not suppose to talk directly from one fragment to another but it's been working with no problem and haven't had time to rewrite everything.

public void setBackground() {

    switch (background) {
    case 0:
        SettingsFrag.rLayout.setBackgroundResource(R.drawable.clay_ul);
        DiceFrag.rLayout.setBackgroundResource(R.drawable.clay_uc);
        DiceLogFrag.rLayout.setBackgroundResource(R.drawable.clay_ur);
        break;
    case 1:
        SettingsFrag.rLayout.setBackgroundResource(R.drawable.parchment_ul);
        DiceFrag.rLayout.setBackgroundResource(R.drawable.parchment_uc);
        DiceLogFrag.rLayout.setBackgroundResource(R.drawable.parchment_ur);
        break;
    case 2:
        SettingsFrag.rLayout.setBackgroundResource(R.drawable.brownpaper_ul);
        DiceFrag.rLayout.setBackgroundResource(R.drawable.brownpaper_uc);
        DiceLogFrag.rLayout.setBackgroundResource(R.drawable.brownpaper_ur);
        break;
    case 3:
        SettingsFrag.rLayout.setBackgroundResource(R.drawable.notebook_ul);
        DiceFrag.rLayout.setBackgroundResource(R.drawable.notebook_uc);
        DiceLogFrag.rLayout.setBackgroundResource(R.drawable.notebook_ur);
        break;
    case 4:
        SettingsFrag.rLayout.setBackgroundColor(Color.WHITE);
        DiceFrag.rLayout.setBackgroundColor(Color.WHITE);
        DiceLogFrag.rLayout.setBackgroundColor(Color.WHITE);
        break;
    }
}

I make sure whenever I call that method that it won't return a null pointer. Any ideas would be great. I can also put more code up if someone wants to see it. Thanks!

4

1 回答 1

2

当我为特定 dpi(即 hdpi、xhdpi ...)创建一个资产时,我得到了这个,确保您的可绘制对象在drawable/drawable-hdpi/drawable-mdpi/等中可用。您可能在一个drawable目录中创建了一个可绘制对象,但不是在那个目录中当前仿真器/设备正在从中提取。

于 2013-01-15T01:46:35.647 回答