【Android】Error: Expected resource of type styleable [ResourceType]

错误提示:

Error: Expected resource of type styleable [ResourceType]

这个错误在编译运行时候并不会出现,但是当需要编译打包的时候,就会爆出这个异常。

这个错误出现的位置位于自定义View中,代码如下:

     TypedArray ta = mContext.obtainStyledAttributes(attrs);

     booleanhasBottomLine = ta.getBoolean(0,false);

     booleanhasTopLine = ta.getBoolean(1,false);

点击异常信息会定位到第三行,只有当 TypedArray 获取第二个属性以后数据时,才会出现此异常,ta.getBoolean(0, false) 这句则不会报错,其实这应该是一个警告,所以才会在调试的时候正常编译,但却在编译签名包的时候失败。

解决办法

解决办法就是在使用TypedArray的方法处,加上@SuppressWarnings(“ResourceType”),这样即可过滤该警告,可以正常通过签名编译。例如:

    @SuppressWarnings("ResourceType")

    publicvoidinitView() {   

    TypedArray ta =  mContext.obtainStyledAttributes(attrs);

    booleanhasBottomLine = ta.getBoolean(0,false);

    booleanhasTopLine = ta.getBoolean(1,false);   

    ta.recycle();}

参考链接

http://stackoverflow.com/questions/26360954/obtainstyledattributes-annotated-with-styleableres-suppress-warnings

作者:付晓龙
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]中的错误提示,出现了RuntimeError: expected scalar type Half but found Float的错误。这个错误通常是由于在使用GPU V100(32GB)对ChatGLM模型进行lora微调时,数据类型不匹配导致的。为了解决这个问题,可以参考引用\[2\]中的解决方案,即将load_in_8bit=True修改为torch_dtype=torch.float16。这样可以将数据类型转换为半精度浮点数,与GPU V100(32GB)的数据类型匹配。另外,还可以检查微调命令中的参数设置,确保使用了正确的数据类型和设备。如果问题仍然存在,可以尝试调整其他参数,如batch size和learning rate等,以优化模型的训练和预测过程。 #### 引用[.reference_title] - *1* *3* [RuntimeError: expected scalar type Half but found Float解决方案](https://blog.csdn.net/weixin_43178406/article/details/130383527)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [MOSS LORA 方式微调报错,RuntimeError: expected scalar type Half but found Float解决方案](https://blog.csdn.net/uloveqian/article/details/130759174)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值