UnsupportedOperationException: Failed to resolve attribute xxx系列的问题
来源:互联网 发布:淘宝开店 平板 编辑:程序博客网 时间:2024/06/18 15:22
接着上篇文章,讲到了有个UnsupportedOperationException的问题
Caused by: java.lang.reflect.InvocationTargetException\\n\\tat java.lang.reflect.Constructor.newInstance(Native Method)\\n\\tat com.elong.mobile.plugin.utils.PluginResInflateFactory.onCreateView(PluginResInflateFactory.java:45)\\n\\t... 38 more \\nCaused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x1010351 a=1}\\n\\tat android.content.res.TypedArray.getColorStateList(TypedArray.java:493)\\n\\tat android.widget.TextView.<init>(TextView.java:1065)\\n\\tat android.widget.EditText.<init>(EditText.java:71)\\n\\tat android.widget.EditText.<init>(EditText.java:66)\\n\\tat android.widget.EditText.<init>(EditText.java:62)\\n\\t... 40 more\\nandroid.view.InflateException: Binary XML file line #61: Binary XML file line #61: Error inflating class android.widget.EditText\\n\\tat android.view.LayoutInflater.inflate(LayoutInflater.java:539)\\n\\tat android.view.LayoutInflater.inflate(LayoutInflater.java:394)\\n\\tat com.elong.android.home.dialogutils.BaseHttpDialog.init(BaseHttpDialog.java:61)\\n\\tat com.elong.android.home.dialogutils.BaseHttpDialog.<init>(BaseHttpDialog.java:31)\\n\\tat com.elong.android.home.dialogutils.HttpVerifyCodeDialog.<init>(HttpVerifyCodeDialog.java:33)\\n\\tat com.elong.android.home.BaseNetFragment.initDialog(BaseNetFragment.java:44)\\n\\tat com.elong.android.home.RevisionHomeActivity.onCreateView(RevisionHomeActivity.java:246)\\n\\tat android.app.Fragment.performCreateView(Fragment.java:2236)\\n\\tat android.app.FragmentManagerImpl.moveToState(FragmentManager.java:978)\\n\\tat android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1153)\\n\\tat android.app.BackStackRecord.run(BackStackRecord.java:800)\\n\\tat android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1562)\\n\\tat android.app.FragmentController.execPendingActions(FragmentController.java:325)\\n\\tat android.app.Activity.performStart(Activity.java:6285)\\n\\tat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2510)\\n\\tat android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2613)\\n\\tat android.app.ActivityThread.-wrap11(ActivityThread.java)\\n\\tat android.app.ActivityThread$H.handleMessage(ActivityThread.java:1469)\\n\\tat android.os.Handler.dispatchMessage(Handler.java:111)\\n\\tat android.os.Looper.loop(Looper.java:207)\\n\\tat android.app.ActivityThread.main(ActivityThread.java:5692)\\n\\tat java.lang.reflect.Method.invoke(Native Method)\\n\\tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)\\n\\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:752)\\n其中最重要的一行就是
java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x1010351 a=1}这个错误是TypedArray代码抛出的
frameworks/base/core/java/android/content/res/TypedArray.java
public ColorStateList getColorStateList(int index) { if (mRecycled) { throw new RuntimeException("Cannot make calls to a recycled instance!"); } final TypedValue value = mValue; if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) { if (value.type == TypedValue.TYPE_ATTRIBUTE) { throw new UnsupportedOperationException( "Failed to resolve attribute at index " + index + ": " + value); } return mResources.loadColorStateList(value, value.resourceId, mTheme); } return null; }可以看出是TypedValue.TYPE_ATTRIBUTE类型就会抛出这个exception
TypeValue其它类型可参见代码,部分代码如下:
/** The <var>data</var> field holds an attribute resource * identifier (referencing an attribute in the current theme * style, not a resource entry). */ public static final int TYPE_ATTRIBUTE = 0x02; /** The <var>string</var> field holds string data. In addition, if * <var>data</var> is non-zero then it is the string block * index of the string and <var>assetCookie</var> is the set of * assets the string came from. */ public static final int TYPE_STRING = 0x03; /** The <var>data</var> field holds an IEEE 754 floating point number. */ public static final int TYPE_FLOAT = 0x04; /** The <var>data</var> field holds a complex number encoding a * dimension value. */ public static final int TYPE_DIMENSION = 0x05;可以看出TypedValue{t=0x2/d=0x1010351 a=1}其中的t=0x2就是指类型为2,其它含义参见代码
public String toString() { StringBuilder sb = new StringBuilder(); sb.append("TypedValue{t=0x").append(Integer.toHexString(type)); sb.append("/d=0x").append(Integer.toHexString(data)); if (type == TYPE_STRING) { sb.append(" \"").append(string != null ? string : "<null>").append("\""); } if (assetCookie != 0) { sb.append(" a=").append(assetCookie); } if (resourceId != 0) { sb.append(" r=0x").append(Integer.toHexString(resourceId)); } sb.append("}"); return sb.toString(); }其中的"a="只对string有意义,这个获取的是color,所以“a=1”没啥含义
/** Additional information about where the value came from; only * set for strings. */ public int assetCookie;其中的d是资源id,framework中的资源id是预先指定好的,app的编译时动态确定。
frameworks/base/core/res/res/values/public.xml
<public type="attr" name="editTextColor" id="0x01010351" />其中的0x1010351就是指editTextColor,报错的原因就是editTextColor最终没有确认成一个确定的值。
原因从EditText的构造方法讲起
public EditText(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)最后一个参数就是控件系统最后获取属性值的地方,默认是空的,但是控件同事指定了一个默认值,这个值是系统定义的一个值,并无修改,但是出错的原因就是这个。
参见frameworks/base/core/res/res/values中定义
<style name="Widget.Material.EditText" parent="Widget.EditText"/>
<style name="Widget.EditText"> <item name="focusable">true</item> <item name="focusableInTouchMode">true</item> <item name="clickable">true</item> <item name="background">?attr/editTextBackground</item> <item name="textAppearance">?attr/textAppearanceMediumInverse</item> <item name="textColor">?attr/editTextColor</item> <item name="gravity">center_vertical</item> <item name="breakStrategy">simple</item> <item name="hyphenationFrequency">normal</item> </style>可以看出textColor 的值就是attr,如果app的主题、app的xml代码、系统的默认attr都没有指定textColor或者editTextColor,那么当然最终会报错。
Android中xml中的属性定义>app主题>控件的第三个参数defStyleAttr>控件的第四个参数defStyleRes,如果四轮都没法确定一个属性的最终值,就会抛出错误。
阅读全文
0 0
- UnsupportedOperationException: Failed to resolve attribute xxx系列的问题
- 使用TextInputLayout所遇到的坑-java.lang.UnsupportedOperationException: Failed to resolve attribute at index
- Failed to resolve attribute at index 6
- ubuntu中unable to resolve host xxx问题的解决方法
- java.lang.RuntimeException: Failed to resolve attribute at index 6
- Android Studio 引入第三方类库的问题failed to resolve
- 解决failed to resolve 各种第三方包的问题
- android---- 引入本地aar 包 failed to resolve:xxx
- Unable to resolve target 'android-8',INSTALL_FAILED_UPDATE_INCOMPATIBLE和failed to start daemon等问题的解决
- Failed to resolve: 之一
- Failed to resolve:aar
- Failed to resolve: com.android.support:appcompat-v7:23.2.0的问题
- Android Studio第一次打开出现的两个问题: Rendering Problems & Failed to resolve: junit
- Failed to resolve: com.android.support:26.X.X 问题的解决
- 源码编译Eclipse-PTP插件遇到Failed to resolve target definition问题的解决方法
- [Android Studio] 解决Module里面调用aar出现Failed to resolve的问题
- [Android Studio] 解决Module里面调用aar出现Failed to resolve的问题
- Android Studio failed to resolve .....
- Lwip IP包分片重组
- 工作3年的程序员应该具备什么技能
- Android应用打包签名上线全过程
- Spring和MyBatis环境整合
- 小兔的棋盘
- UnsupportedOperationException: Failed to resolve attribute xxx系列的问题
- 底部展示选项
- 粒子显示在UI前方
- 实时网络游戏《商人》开发笔记
- 【PHP】高级面试题之十万个为什么?(二)
- [转]Qt中添加OpenGL库
- shell数组和declare用法
- Git分支概念
- 分针网—每日分享:PHP接入支付宝教程