资源未找到异常:资源不是可绘制项(颜色或路径)?

54

我有一个TextView,当它被点击时,我会在对话框内填充一个ListView。这段代码以前一直能正常工作,但今天却抛出了异常。

以下是我的代码:

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();
        }
    });

日志记录错误显示如下:

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)

无法解决问题。请帮忙吗?

那是 DailyQuotesWidgetConfigureActivity.java 的第 182 行吗? - Blackbelt
嗨,第182行是这样的:ListView listView = new ListView(context); listView.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1, new String[] {"默认", "衬线体", "等宽字体"})); - Bluemarble
@BuggyCoder:请尝试使用dialog.setTitle(v.getContext().getResources().getString(R.string.txt_settings_QuotefontName))代替dialog.setTitle(R.string.txt_settings_QuotefontName) - ρяσѕρєя K
1
当我升级使用compile'com.android.support:appcompat-v7:23.4.0'时,我遇到了这个问题,如果我保留v7:22.2.0',它就能正常工作。 - tread
12个回答

0
<ImageView
...
            android:src="@drawable/realtconsult" />

如果你从一个角度来写的话,这样就会起作用。

-1

将所有的ic_xyz.xml文件夹移动到drawable(v24)中,即选择您遇到问题的文件夹并将其移动到或选择-->重构-->移动文件-->(更改路径)到Drawable(v24)。


我做了相反的事情,它起作用了。(从v24移动到普通文件夹)。 - Behnawwm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接