最近開(kāi)發(fā)的時(shí)候遇到這么一個(gè)崩潰弊添,找了半天原因終于找到問(wèn)題的原因债鸡。
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
主要的問(wèn)題是這個(gè)
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f0302a9 a=2}
這個(gè)錯(cuò)誤是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類型就會(huì)拋出這個(gè)exception
可以看出TypedValue{t=0x2/d=0x1010351 a=1}其中的t=0x2就是指類型為2,其它含義參見(jiàn)代碼
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="只對(duì)string有意義庸论,這個(gè)獲取的是color职辅,所以“a=1”沒(méi)啥含義
/** Additional information about where the value came from; only
* set for strings. */
public int assetCookie;
其中的d是資源id,framework中的資源id是預(yù)先指定好的聂示,app的編譯時(shí)動(dòng)態(tài)確定域携。
frameworks/base/core/res/res/values/public.xml
<public type="attr" name="background" id="0x7f0302a9" />
其中的0x7f0302a9就是指background,報(bào)錯(cuò)的原因就是background最終沒(méi)有確認(rèn)成一個(gè)確定的值鱼喉。
出現(xiàn)這個(gè)原因主要是因?yàn)橐昧薗mui的ui庫(kù)秀鞭,但是activity的theme沒(méi)有繼承QMUI.Compat.NoActionBar,所以導(dǎo)致設(shè)置背景的時(shí)候找不到對(duì)應(yīng)的資源出現(xiàn)的這個(gè)問(wèn)題扛禽。繞了很大一圈锋边,這里記錄一下問(wèn)題。