2

我在硬盘驱动器崩溃后升级了我的构建工具,现在我的 MainActivity 在 setContentView() 中对 ActionBar 进行膨胀时出现运行时错误。这是日志猫:

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

它试图在 appcompat 支持库中初始化 ActionBarContainer,并在 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 库中携带。

我正在使用支持库 v23.1 中的 Eclipse Mars 4.5.0、ADT 23.0.7.2120684 和 appcompat.v7。我在运行 API 17(Android 4.2.2)的 Tesco Hudl 7" 平板电脑上构建和测试 API 23。

有任何想法吗?

4

0 回答 0