美文网首页Android Other
UnsupportedOperationException: F

UnsupportedOperationException: F

作者: Merlin_720 | 来源:发表于2019-10-12 14:25 被阅读0次

最近开发的时候遇到这么一个崩溃,找了半天原因终于找到问题的原因。

Caused by: android.view.InflateException: Binary XML file line #33: Error inflating class com.qmuiteam.qmui.widget.dialog.QMUIDialogView                                                                    
Caused by: java.lang.reflect.InvocationTargetException                                                                                                                                                      
    at java.lang.reflect.Constructor.newInstance0(Native Method)                                                                                                                                            
    at java.lang.reflect.Constructor.newInstance(Constructor.java:334)                                                                                                                                      
    at android.view.LayoutInflater.createView(LayoutInflater.java:647)                                                                                                                                      
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)                                                                                                                               
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)                                                                                                                               
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)                                                                                                                                        
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)                                                                                                                                
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)                                                                                                                                         
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)                                                                                                                                         
    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)                                                                                                                                         
    at com.qmuiteam.qmui.widget.dialog.QMUIDialogBuilder.create(QMUIDialogBuilder.java:318)                                                                                                                 
    at com.easy.easycan.me.ProfileFragment.contactService(ProfileFragment.java:224)                                                                                                                         
    at com.easy.easycan.me.ProfileFragment.access$100(ProfileFragment.java:63)                                                                                                                              
    at com.easy.easycan.me.ProfileFragment$5.accept(ProfileFragment.java:177)                                                                                                                               
    at io.reactivex.internal.observers.LambdaObserver.onNext(LambdaObserver.java:63)                                                                                                                        
    at io.reactivex.observers.SerializedObserver.onNext(SerializedObserver.java:111)                                                                                                                        
    at io.reactivex.internal.operators.observable.ObservableThrottleFirstTimed$DebounceTimedObserver.onNext(ObservableThrottleFirstTimed.java:82)                                                           
    at com.jakewharton.rxbinding2.view.ViewClickObservable$Listener.onClick(ViewClickObservable.java:39)                                                                                                    
    at android.view.View.performClick(View.java:6294)                                                                                                                                                       
    at android.view.View$PerformClick.run(View.java:24770)                                                                                                                                                  
    at android.os.Handler.handleCallback(Handler.java:790)                                                                                                                                                  
    at android.os.Handler.dispatchMessage(Handler.java:99)                                                                                                                                                  
    at android.os.Looper.loop(Looper.java:164)                                                                                                                                                              
    at android.app.ActivityThread.main(ActivityThread.java:6494)                                                                                                                                            
    at java.lang.reflect.Method.invoke(Native Method)                                                                                                                                                       
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)                                                                                                                    
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)                                                                                                                                         
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0302a9 a=2}                                                                             
    at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:944)                                                                                                                            
    at android.content.res.TypedArray.getDrawable(TypedArray.java:928)                                                                                                                                      
    at android.view.View.<init>(View.java:4768)                                                                                                                                                             
    at android.view.ViewGroup.<init>(ViewGroup.java:597)                                                                                                                                                    
    at android.widget.LinearLayout.<init>(LinearLayout.java:234)                                                                                                                                            
    at android.widget.LinearLayout.<init>(LinearLayout.java:230)                                                                                                                                            
    at com.qmuiteam.qmui.alpha.QMUIAlphaLinearLayout.<init>(QMUIAlphaLinearLayout.java:39)                                                                                                                  
    at com.qmuiteam.qmui.layout.QMUILinearLayout.<init>(QMUILinearLayout.java:45)                                                                                                                           
    at com.qmuiteam.qmui.widget.dialog.QMUIDialogView.<init>(QMUIDialogView.java:48)                                                                                                                        
    at com.qmuiteam.qmui.widget.dialog.QMUIDialogView.<init>(QMUIDialogView.java:44)                                                                                                                        
    ... 27 more                                                                                                                                                                                                
                                                                                                                                                                                                            

主要的问题是这个

Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0302a9 a=2}

这个错误是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
可以看出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="background" id="0x7f0302a9" />

其中的0x7f0302a9就是指background,报错的原因就是background最终没有确认成一个确定的值。
出现这个原因主要是因为引用了Qmui的ui库,但是activity的theme没有继承QMUI.Compat.NoActionBar,所以导致设置背景的时候找不到对应的资源出现的这个问题。绕了很大一圈,这里记录一下问题。

相关文章

网友评论

    本文标题:UnsupportedOperationException: F

    本文链接:https://www.haomeiwen.com/subject/uiuqmctx.html