UnsupportedOperationException в getDimensionPixelSize() при накачке ActionBar в appcompat v23.1
Я обновил свои инструменты сборки после сбоя жесткого диска и теперь получаю ошибку во время выполнения в моем MainActivity, когда он надувает ActionBar в setContentView(). Вот логкат:
11-05 09:37:11.607: W/dalvikvm(15472): threadid=1: thread exiting with uncaught exception (group=0x40caa930)
11-05 09:37:11.717: E/AndroidRuntime(15472): FATAL EXCEPTION: main
11-05 09:37:11.717: E/AndroidRuntime(15472): java.lang.RuntimeException: Unable to start activity ComponentInfo{uk.co.seatrack.seatracklite/uk.co.seatrack.seatracklite.MainActivity}: android.view.InflateException: Binary XML file line #27: Error inflating class android.support.v7.internal.widget.ActionBarContainer
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.ActivityThread.access$600(ActivityThread.java:141)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.os.Handler.dispatchMessage(Handler.java:99)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.os.Looper.loop(Looper.java:137)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.ActivityThread.main(ActivityThread.java:5041)
11-05 09:37:11.717: E/AndroidRuntime(15472): at java.lang.reflect.Method.invokeNative(Native Method)
11-05 09:37:11.717: E/AndroidRuntime(15472): at java.lang.reflect.Method.invoke(Method.java:511)
11-05 09:37:11.717: E/AndroidRuntime(15472): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-05 09:37:11.717: E/AndroidRuntime(15472): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-05 09:37:11.717: E/AndroidRuntime(15472): at dalvik.system.NativeStart.main(Native Method)
11-05 09:37:11.717: E/AndroidRuntime(15472): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class android.support.v7.internal.widget.ActionBarContainer
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:359)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:280)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:254)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
11-05 09:37:11.717: E/AndroidRuntime(15472): at uk.co.seatrack.seatracklite.MainActivity.onCreate(MainActivity.java:169)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.Activity.performCreate(Activity.java:5104)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
11-05 09:37:11.717: E/AndroidRuntime(15472): ... 11 more
11-05 09:37:11.717: E/AndroidRuntime(15472): Caused by: java.lang.reflect.InvocationTargetException
11-05 09:37:11.717: E/AndroidRuntime(15472): at java.lang.reflect.Constructor.constructNative(Native Method)
11-05 09:37:11.717: E/AndroidRuntime(15472): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
11-05 09:37:11.717: E/AndroidRuntime(15472): ... 24 more
11-05 09:37:11.717: E/AndroidRuntime(15472): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
11-05 09:37:11.717: E/AndroidRuntime(15472): at android.support.v7.internal.widget.ActionBarContainer.<init>(ActionBarContainer.java:68)
11-05 09:37:11.717: E/AndroidRuntime(15472): ... 27 more
Он пытается инициализировать ActionBarContainer в библиотеке поддержки appcompat и получает ошибку в getDimensionPixelSize. Соответствующий код в библиотеке выглядит следующим образом:
public ActionBarContainer(Context context, AttributeSet attrs) {
super(context, attrs);
// Set a transparent background so that we project appropriately.
final Drawable bg = VersionUtils.isAtLeastL()
? new ActionBarBackgroundDrawableV21(this)
: new ActionBarBackgroundDrawable(this);
setBackgroundDrawable(bg);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.ActionBar);
mBackground = a.getDrawable(R.styleable.ActionBar_background);
mStackedBackground = a.getDrawable(
R.styleable.ActionBar_backgroundStacked);
>>>> mHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height, -1); <<<<
if (getId() == R.id.split_action_bar) {
mIsSplit = true;
mSplitBackground = a.getDrawable(R.styleable.ActionBar_backgroundSplit);
}
a.recycle();
setWillNotDraw(mIsSplit ? mSplitBackground == null :
mBackground == null && mStackedBackground == null);
}
getDimensionPixelSize () ожидает, что ресурс будет TypedArray.TYPE_DIMENSION, но на самом деле он получает TypedArray.TYPE_ATTRIBUTE, и поэтому он выбрасывает. Ресурс, который он ищет (R.styleable.ActionBar_height), определен в файле библиотеки appcompat /res/values/attrs.xml:
<declare-styleable name="ActionBar">
<!-- The type of navigation to use. -->
<attr name="navigationMode">
<!-- Normal static title text -->
<enum name="normal" value="0"/>
<!-- The action bar will use a selection list for navigation. -->
<enum name="listMode" value="1"/>
<!-- The action bar will use a series of horizontal tabs for navigation. -->
<enum name="tabMode" value="2"/>
</attr>
<!-- Options affecting how the action bar is displayed. -->
<attr name="displayOptions">
<flag name="none" value="0" />
<flag name="useLogo" value="0x1"/>
<flag name="showHome" value="0x2"/>
<flag name="homeAsUp" value="0x4"/>
<flag name="showTitle" value="0x8"/>
<flag name="showCustom" value="0x10"/>
<flag name="disableHome" value="0x20"/>
</attr>
<!-- Specifies title text used for navigationMode="normal" -->
<attr name="title"/>
<!-- Specifies subtitle text used for navigationMode="normal" -->
<attr name="subtitle" format="string"/>
<!-- Specifies a style to use for title text. -->
<attr name="titleTextStyle" format="reference"/>
<!-- Specifies a style to use for subtitle text. -->
<attr name="subtitleTextStyle" format="reference"/>
<!-- Specifies the drawable used for the application icon. -->
<attr name="icon" format="reference"/>
<!-- Specifies the drawable used for the application logo. -->
<attr name="logo" format="reference"/>
<!-- Specifies the drawable used for item dividers. -->
<attr name="divider" format="reference"/>
<!-- Specifies a background drawable for the action bar. -->
<attr name="background" format="reference"/>
<!-- Specifies a background drawable for a second stacked row of the action bar. -->
<attr name="backgroundStacked" format="reference|color"/>
<!-- Specifies a background drawable for the bottom component of a split action bar. -->
<attr name="backgroundSplit" format="reference|color"/>
<!-- Specifies a layout for custom navigation. Overrides navigationMode. -->
<attr name="customNavigationLayout" format="reference"/>
<!-- Specifies a fixed height. -->
<!-- MCAJ - added format -->
<attr name="height" format="dimension"/>
где я добавил format="dimension"
к оригиналу, в котором отсутствовал какой-либо формат. Это не решило проблему!
Файл app bin/R.txt содержит строку:
int styleable ActionBar_height 14
поэтому ресурс был перенесен из библиотеки appcompat во время сборки.
Я использую Eclipse Mars 4.5.0, ADT 23.0.7.2120684 и appcompat.v7 из библиотеки поддержки v23.1. Я собираюсь использовать API 23 при сборке и тестировании на планшете Tesco Hudl 7"с API 17 (Android 4.2.2).
Есть идеи?