错误:可样式化[ResourceType]类型的预期资源错误 [英] Error: Expected resource of type styleable [ResourceType] error

查看:365
本文介绍了错误:可样式化[ResourceType]类型的预期资源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看此代码段. 我在最后一行出现错误,因为我传递的是索引"而不是资源.我认为这是一个不起毛的问题,并试图压制它. 然后,我注意到只有在进行发行时才收到此错误.在进行调试时可以正常工作.我完全一无所知.谁能告诉我我做错了什么.

Take a look at this code snippet. I am getting an error with the last line, because I am passing an 'index' instead of a resource. I thought it was a lint issue and tried to suppress it. Then I noticed I am getting this error only when I building for release. It works fine when building for debug. I am totally clueless. Can anyone throw some light into what I am doing wrong.

//Get paddingLeft, paddingRight
        int[] attrsArray = new int[]{
                android.R.attr.paddingLeft,  // 0
                android.R.attr.paddingRight, // 1
        };
        TypedArray ta = context.obtainStyledAttributes(attrs, attrsArray);
        if (ta == null) return;
        mPaddingLeft = ta.getDimensionPixelSize(0, 0);
        mPaddingRight = ta.getDimensionPixelSize(1/*error here*/, 0); 

推荐答案

在尝试构建签名的apk时,我遇到了同样的问题. 通过添加@SuppressWarnings("ResourceType")禁止显示警告来解决该问题,现在可以正常使用了.

I had the same issue when trying to build a signed apk. Solved it by adding @SuppressWarnings("ResourceType") to suppress the warning, now it works fine.

这篇关于错误:可样式化[ResourceType]类型的预期资源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆