本文介绍了Resources $ NotFoundException:资源不是Drawable(颜色或路径)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个textview,单击它时,我正在对话框中填充listView.这段代码过去工作正常,但今天却抛出异常.

I have a textview, when it is clicked, I am populating a listView inside a dialog. This code used to work fine, but today it is throwing exception.

这是我的代码:

tvSelectedFont = (TextView)findViewById(R.id.lblQuoteSelectedFont);
    tvSelectedFont.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            ListView listView = new ListView(context);
            listView.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1,
                    new String[] {"Default", "Serif", "Monospace"}));
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(listView);
            dialog.setTitle(R.string.txt_settings_QuotefontName);

            listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    String selectedTypeFace = ((TextView)view).getText().toString();
                    tvSelectedFont.setText(selectedTypeFace);
                    switch(selectedTypeFace)
                    {
                        case "Serif":
                            selectedQuoteTypeFace = Typeface.SERIF;
                            break;
                        case "Monospace":
                            selectedQuoteTypeFace = Typeface.MONOSPACE;
                            break;
                        default:
                            selectedQuoteTypeFace = Typeface.DEFAULT;
                            break;
                    }
                    tvQuoteTextSample.setTypeface(selectedQuoteTypeFace, selectedQuoteFontStyle);
                    dialog.dismiss();
                }
            });

            dialog.show();
        }
    });

logcat错误显示以下内容:

The logcat error shows this:

Device driver API version: 29
User space API version: 29
03-17 14:33:24.701  23220-23220/com.example.manas.dailyquoteswidget E/﹕ mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Tue Jul 22 19:59:34 KST 2014
03-17 14:33:27.926  23220-23220/com.example.manas.dailyquoteswidget E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.manas.dailyquoteswidget, PID: 23220
android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f0100a7 a=3}
        at android.content.res.Resources.loadDrawable(Resources.java:3415)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
        at android.widget.AbsListView.<init>(AbsListView.java:1089)
        at android.widget.ListView.<init>(ListView.java:152)
        at android.widget.ListView.<init>(ListView.java:148)
        at android.widget.ListView.<init>(ListView.java:144)
        at com.example.manas.dailyquoteswidget.DailyQuotesWidgetConfigureActivity$6.onClick(DailyQuotesWidgetConfigureActivity.java:182)
        at android.view.View.performClick(View.java:4640)
        at android.view.View$PerformClick.run(View.java:19425)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:146)
        at android.app.ActivityThread.main(ActivityThread.java:5593)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
        at dalvik.system.NativeStart.main(Native Method)

不能弄清楚问题所在.有什么帮助吗?

Cant figure it out the problem. Any help please?

推荐答案

我在最近制作的应用中遇到了此问题.就我而言,问题是我将图像放在名为drawable-v21的文件夹中,该图像在较旧的android API中不可用.

I encountered this problem in the recent app I made. In my case, the problem was I put an image in the folder called drawable-v21, which is not available in older android API.

解决方案是将可绘制对象也放置在drawable -... dpi文件夹中.

The solution is to put your drawable in drawable-...dpi folders too.

希望有帮助.

这篇关于Resources $ NotFoundException:资源不是Drawable(颜色或路径)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 19:02