安卓UnsupportedOperationException异常:无法转换为彩色:类型= 0X2

编程入门 行业动态 更新时间:2024-10-09 08:25:42
本文介绍了安卓UnsupportedOperationException异常:无法转换为彩色:类型= 0X2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是从Android Market的崩溃日志:

This is the crashlog from Android Market:

android.view.InflateException: Binary XML file line #8: Error inflating class <unknown> at android.view.LayoutInflater.createView(LayoutInflater.java:596) at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56) at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669) at android.view.LayoutInflater.rInflate(LayoutInflater.java:724) at android.view.LayoutInflater.inflate(LayoutInflater.java:479) at android.view.LayoutInflater.inflate(LayoutInflater.java:391) at android.view.LayoutInflater.inflate(LayoutInflater.java:347) at com.designfuture.music.ui.dialog.MXMDialog.<init>(MXMDialog.java:73) at com.designfuture.music.ui.dialog.MXMDialog.<init>(MXMDialog.java:58) at com.designfuture.music.model.MXMStoreBuy.getBuyDialog(MXMStoreBuy.java:70) at com.designfuture.music.ui.fragment.plbl.XLBLFragment$ViewHolder$3.onClick(XLBLFragment.java:290) at android.view.View.performClick(View.java:3110) at android.view.View$PerformClick.run(View.java:11934) at android.os.Handler.handleCallback(Handler.java:587) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:132) at android.app.ActivityThread.main(ActivityThread.java:4123) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:491) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:416) at android.view.LayoutInflater.createView(LayoutInflater.java:576) ... 22 more Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2 at android.content.res.TypedArray.getColor(TypedArray.java:326) at android.widget.TextView.<init>(TextView.java:422) at android.widget.TextView.<init>(TextView.java:364) ... 25 more

因此​​,对于我所看到的问题是在

So for what I can see the problem is in

at com.designfuture.music.ui.dialog.MXMDialog.<init>(MXMDialog.java:73)

在那里我有这行code:

Where I have this line of code:

mHolder = new ViewHolder((ViewGroup) inflater.inflate(R.layout.dialog_mxm, null));

这是完整的功能

public MXMDialog(Context context, String title) { super( context, R.style.Dialog_MXM ); //getWindow() LayoutParams lp= getWindow().getAttributes(); lp.gravity = Gravity.CENTER; lp.dimAmount = 0.5f; lp.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL; if(inflater == null) inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); mHolder = new ViewHolder((ViewGroup) inflater.inflate(R.layout.dialog_mxm, null)); super.setContentView(mHolder.root); if(title != null) setTitle(title); }

这是R.layout.dialog_mxm

This is the content of the R.layout.dialog_mxm

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="schemas.android/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@android:id/title" android:background="@drawable/tabwidget" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" android:gravity="left" android:paddingLeft="10dp" android:textStyle="bold" android:textColor="@color/orange_mxm" style="@android:style/TextAppearance.Large"/> <FrameLayout android:id="@android:id/content" android:background="@drawable/tabwidget" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>

我认为这个问题是在TextView中。 该TextView中的样式不能是一个问题,因为直接来自Android的,所以我不认为这将是一个问题。

I think that the problem is in the TextView. The style of that textview cannot be a problem because comes directly from Android so I don't think this will be a problem.

Android的:文字颜色=@色/ orange_mxm这是在我的colors.xml

The android:textColor="@color/orange_mxm" is this in my colors.xml

<color name="orange_mxm">#FFff6500</color>

这是Dialog.MXM风格

This is the Dialog.MXM style

<!-- DIALOG --> <style name="Dialog.MXM" parent="@android:style/Theme.DeviceDefault.Dialog"> <item name="android:layout_width">wrap_content</item> <item name="android:background">@android:color/transparent</item> <item name="android:windowAnimationStyle">@style/Dialog.MXM.FadeAnimation</item> <item name="android:windowIsFloating">true</item> <item name="android:windowNoTitle">true</item> <item name="android:gravity">center</item> </style> <style name="Dialog.MXM.FadeAnimation"> <item name="android:windowEnterAnimation">@android:anim/fade_in</item> <item name="android:windowExitAnimation">@android:anim/fade_out</item> </style>

和我不认为这是一个如此不标准的颜色...

And I don't think this is a so not-standard color...

在哪里的问题?我该如何解决这个问题?

Where's the problem? How can I solve this?

推荐答案

请问Dialog.MXM风格随API级别的设备支持(例如使用值-V14 /目录下),或者是用于所有设备?

Does the Dialog.MXM style vary with the API level supported by the device (e.g. using a values-v14/ directory) or is it used for all devices?

在DeviceDefault主题系列(包括Theme.DeviceDefault.Dialog)于14 API添加(安卓4.0 ICS),并不会对旧设备present。这意味着在那些其中该主题不能找到的设备,Dialog.MXM实际上有一个空父主题。主题想到一些属性已经定义的值,在这种情况下,你的主题将缺少很多必要的。有些设备可能处理这个更优雅比其他人。

The DeviceDefault theme family (including Theme.DeviceDefault.Dialog) was added in API 14 (Android 4.0, ICS) and will not be present on older devices. This means that on those devices where that theme cannot be found, Dialog.MXM in effect has a null parent theme. Themes expect a number of attributes to have defined values, and in this case your theme will be missing many required ones. Some devices may deal with this more gracefully than others.

的一个解决方案是定义一种共同的基本主题,从不同的父继承基于所述设备运行的哪个平台版本。举个例子:

One solution is to define a common base theme that inherits from a different parent based on which platform version the device is running. An example:

RES /价值/的themes.xml:

res/values/themes.xml:

[...] <!-- Use the legacy dialog theme as a base on older devices --> <style name="Dialog.Base" parent="@android:style/Theme.Dialog" /> <!-- Dialog.Base varies with platform version --> <style name="Dialog.MXM" parent="@style/Dialog.Base"> <item name="android:background">@android:color/transparent</item> <item name="android:windowAnimationStyle">@style/Dialog.MXM.FadeAnimation</item> <item name="android:windowIsFloating">true</item> <item name="android:windowNoTitle">true</item> <item name="android:gravity">center</item> </style> [...]

RES /值-V11 /的themes.xml:

res/values-v11/themes.xml:

[...] <!-- Use Holo dialogs as the base on Honeycomb --> <style name="Dialog.Base" parent="@android:style/Theme.Holo.Dialog" /> [...]

RES /值-V14 /的themes.xml:

res/values-v14/themes.xml:

[...] <!-- Use DeviceDefault dialogs as the base on ICS and newer --> <style name="Dialog.Base" parent="@android:style/Theme.DeviceDefault.Dialog" /> [...]

更多推荐

安卓UnsupportedOperationException异常:无法转换为彩色:类型= 0X2

本文发布于:2023-11-26 05:17:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   异常   彩色   类型   UnsupportedOperationException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!