3

我正在使用 Sherlock 库在预 HoneyComb 设备上放置操作栏。奇怪的是,错误只发生在某些设备上。或更好。似乎在模拟器 2.3.3 上有效,但在 LG Optimus P500 2.3.3 上显示以下错误(Android_InfocadActivity 类是我的活动):

java.lang.RuntimeException: Unable to start activity ComponentInfo{android.infocad.com/android.infocad.com.Android_InfocadActivity}: android.view.InflateException: Binary XML
file line #31: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3729)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(SourceFile:1045)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(SourceFile:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(SourceFile:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SourceFile:229)
at android.infocad.com.Android_InfocadActivity.onCreate(SourceFile:158)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 24 more
Caused by: java.lang.NoSuchMethodError: android.content.res.XmlResourceParser.i
at com.actionbarsherlock.internal.widget.ActionBarView.loadLogoFromManifest(SourceFile:286)
at com.actionbarsherlock.internal.widget.ActionBarView.<init>(SourceFile:193)
... 27 more
android.view.InflateException: Binary XML file line #31: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(SourceFile:1045)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(SourceFile:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(SourceFile:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SourceFile:229)
at android.infocad.com.Android_InfocadActivity.onCreate(SourceFile:158)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3729)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
... 24 more
Caused by: java.lang.NoSuchMethodError: android.content.res.XmlResourceParser.i
at com.actionbarsherlock.internal.widget.ActionBarView.loadLogoFromManifest(SourceFile:286)
at com.actionbarsherlock.internal.widget.ActionBarView.<init>(SourceFile:193)
... 27 more
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(SourceFile:1045)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(SourceFile:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(SourceFile:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SourceFile:229)
at android.infocad.com.Android_InfocadActivity.onCreate(SourceFile:158)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3729)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchMethodError: android.content.res.XmlResourceParser.i
at com.actionbarsherlock.internal.widget.ActionBarView.loadLogoFromManifest(SourceFile:286)
at com.actionbarsherlock.internal.widget.ActionBarView.<init>(SourceFile:193)
... 27 more
java.lang.NoSuchMethodError: android.content.res.XmlResourceParser.i
at com.actionbarsherlock.internal.widget.ActionBarView.loadLogoFromManifest(SourceFile:286)
at com.actionbarsherlock.internal.widget.ActionBarView.<init>(SourceFile:193)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
at android.view.LayoutInflater.createView(LayoutInflater.java:505)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(SourceFile:1045)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(SourceFile:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(SourceFile:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SourceFile:229)
at android.infocad.com.Android_InfocadActivity.onCreate(SourceFile:158)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3729)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:632)

在我的代码中,调用 setContentView 时会显示错误。这是xml布局:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:id="@+id/mainRootLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <LinearLayout
            android:id="@+id/myCustomTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/DarkGray" >
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="left" >
                <ImageView
                    android:id="@+id/main_scadenze"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:src="@drawable/ic_notify_title" />
                <ImageView
                    android:id="@+id/main_nfc"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:src="@drawable/ic_nfc_title" />
                <ImageView
                    android:id="@+id/main_offline"
                    android:layout_width="24dp"
                    android:layout_height="24dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:src="@drawable/ic_offline" />
            </LinearLayout>
        </LinearLayout>
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="70dp"
            android:layout_marginBottom="3dp" />
        <LinearLayout
            android:id="@+id/checkLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/SteelBlue" >
            <ImageView
                android:id="@+id/imageView1"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_gravity="center"
                android:layout_marginLeft="5dp"
                android:src="@drawable/ic_filter" />
            <CheckBox
                android:id="@+id/ticketBox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:text="Ticket" />
            <CheckBox
                android:id="@+id/NCbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:text="NC" />
            <CheckBox
                android:id="@+id/PlanBox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:text="Plan" />
        </LinearLayout>
        <LinearLayout
            android:id="@+id/orderLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="5dp"
                android:src="@drawable/sort_icon" />
            <CheckBox
                android:id="@+id/tipo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="8dp"
                android:text="Prot." />
            <CheckBox
                android:id="@+id/edificio"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="2dp"
                android:text="Edificio" />
            <CheckBox
                android:id="@+id/urgenza"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="14dp"
                android:text="Urgenza" />
        </LinearLayout>
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout
                android:id="@+id/linearLayoutTab1"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
                <ListView
                    android:id="@+id/listView1"
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />
                <LinearLayout
                    android:id="@+id/buttonLayoutTab1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/linearLayoutTab2"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
                <ListView
                    android:id="@+id/myWorkList"
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1" />
              <LinearLayout
                    android:id="@+id/buttonLayoutTab2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >
                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:id="@+id/linearLayoutTab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
             <ViewFlipper
                    android:id="@+id/viewFlipperChiusi"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
                    <LinearLayout
                        android:id="@+id/layout_flipper_chiusi"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >
                     <Button
                            android:id="@+id/SincronizzaButton"
                            android:layout_width="115dp"
                            android:layout_height="50dp"
                            android:layout_gravity="center"
                            android:background="@drawable/aqua_button"
                            android:text="SINCRONIZZA"
                            android:textColor="@color/White"
                            android:textStyle="bold" />
                        <ListView
                            android:id="@+id/listInterventiChiusi"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent" >
                        </ListView>
                    </LinearLayout>
                    <LinearLayout
                        android:id="@+id/layout_flipper_risolti"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >
                        <TextView
                            android:id="@+id/textView1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="5dp"
                            android:text="Storico lavori:"
                            android:textAppearance="?android:attr/textAppearanceMedium" />
                        <ListView
                            android:id="@+id/listRisolto"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent" >
                        </ListView>                    
                   </LinearLayout>
                </ViewFlipper>
            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>

这是一小段代码:

    @Override
    public void onCreate(Bundle savedInstanceState) {

        if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){

            Log.i("VERSION.SDK_INT", "NON e' ICS !!!!");
            this.setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
        }

        super.onCreate(savedInstanceState);

        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

        setContentView(R.layout.main);

        actionBar = getSupportActionBar();
        actionBar.show();
            ....
    }

这是 Proguard 文件:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-dontwarn android.support.v4.**
-dontwarn android.support.v4.view.**
-dontwarn org.xmlpull.v1.**
-dontwarn **CompatHoneycomb

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }

-keepattributes *Annotation*

-keep class android.support.v4.** { *; }

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

#ACRA specifics
# we need line numbers in our stack traces otherwise they are pretty useless
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

# ACRA needs "annotations" so add this... 
-keepattributes *Annotation*

# keep this class so that logging will show 'ACRA' and not a obfuscated name like 'a'.
# Note: if you are removing log messages elsewhere in this file then this isn't necessary
-keep class org.acra.ACRA {
    *;
}

# keep this around for some enums that ACRA needs
-keep class org.acra.ReportingInteractionMode {
    *;
}
-keepnames class org.acra.ReportField {
    *;
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void addCustomData(java.lang.String,java.lang.String);
    public void putCustomData(java.lang.String,java.lang.String);
    public void removeCustomData(java.lang.String);
}

# keep this otherwise it is removed by ProGuard
-keep public class org.acra.ErrorReporter
{
    public void handleSilentException(java.lang.Throwable);
}

顺便说一句,错误似乎来自 Sherlock 库。

我把这个这个都变红了,但与我的相比,错误几乎没有什么不同。在他们的代码中,我看到了NullPointerException。在我有一个NoSuchMethodError: android.content.res.XmlResourceParser.i代替。希望可以有人帮帮我

4

2 回答 2

1

您不应该在布局中包含这样的视图。如果您希望拥有一个 SherlockActionBar,只需从 扩展您的ActivitySherlockActivity,并将主题应用于 AndroidManifest.xml 中的应用程序:

<application
        android:icon="@drawable/logo"
        android:label="@string/app_name"
        android:theme="@style/Theme.Sherlock" >

然后,您将拥有一个 ActionBar。

于 2012-11-15T09:31:11.187 回答
0

使用最新的 android 支持库。

复制这个:...\android-sdk\extras\android\support\v13\android-support-v13.jar

进入您的 libs 文件夹(来自 actionbarsherlock)并删除旧文件夹!

于 2013-10-20T15:49:34.323 回答