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

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

问题描述

看看这个代码片段.最后一行出现错误,因为我传递的是索引"而不是资源.我认为这是一个 lint 问题并试图压制它.然后我注意到我只有在构建发布时才会收到此错误.在构建调试时它工作正常.我完全一窍不通.任何人都可以对我做错的事情有所了解.

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天全站免登陆