ActionBarSherlock和放大器; ShareActionProvider引起InflateException(找到原因,解决不了) [英] ActionBarSherlock & ShareActionProvider cause InflateException (Found cause, not solved)

查看:588
本文介绍了ActionBarSherlock和放大器; ShareActionProvider引起InflateException(找到原因,解决不了)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个构建使用ActionBarSherlock一个应用程序,它的ShareActionProvider产生的意图,其他应用程序。我创建了一个基于从库的GitHub的网页样本code项;起初,我准确无误地运行。然而,在那之后一天,它只是停止工作。如果我删除关于菜肴的通胀通常是活动加载code,否则有以下异常崩溃:

I'm a building an app that uses ActionBarSherlock and it's ShareActionProvider for generating an Intent to other apps. I created the item based on the sample code from the library's github page; at first, I worked flawlessly. However, a day after that, it simply stopped working. If I remove the code regarding the menu inflation the activity loads normally, otherwise it crashes with the following exception:

05-31 22:28:41.200: E/AndroidRuntime(15874): FATAL EXCEPTION: main
05-31 22:28:41.200: E/AndroidRuntime(15874): android.view.InflateException: Binary XML file line #26: Error inflating class <unknown>
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.actionbarsherlock.widget.ActivityChooserView.<init>(ActivityChooserView.java:229)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.actionbarsherlock.widget.ActivityChooserView.<init>(ActivityChooserView.java:202)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.actionbarsherlock.widget.ActivityChooserView.<init>(ActivityChooserView.java:192)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.actionbarsherlock.widget.ShareActionProvider.onCreateActionView(ShareActionProvider.java:164)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.actionbarsherlock.internal.view.ActionProviderWrapper.onCreateActionView(ActionProviderWrapper.java:23)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.ActionProvider.onCreateActionView(ActionProvider.java:98)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:235)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:513)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1048)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:91)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:268)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:244)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:946)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:969)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:488)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:819)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:3148)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.os.Handler.handleCallback(Handler.java:615)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.os.Looper.loop(Looper.java:137)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.app.ActivityThread.main(ActivityThread.java:4898)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at java.lang.reflect.Method.invokeNative(Native Method)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at java.lang.reflect.Method.invoke(Method.java:511)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at dalvik.system.NativeStart.main(Native Method)
05-31 22:28:41.200: E/AndroidRuntime(15874): Caused by: java.lang.reflect.InvocationTargetException
05-31 22:28:41.200: E/AndroidRuntime(15874):    at java.lang.reflect.Constructor.constructNative(Native Method)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-31 22:28:41.200: E/AndroidRuntime(15874):    ... 33 more
05-31 22:28:41.200: E/AndroidRuntime(15874): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f01000f a=-1}
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.content.res.Resources.loadDrawable(Resources.java:1925)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.View.<init>(View.java:3436)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.view.ViewGroup.<init>(ViewGroup.java:432)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.widget.FrameLayout.<init>(FrameLayout.java:101)
05-31 22:28:41.200: E/AndroidRuntime(15874):    at android.widget.FrameLayout.<init>(FrameLayout.java:97)
05-31 22:28:41.200: E/AndroidRuntime(15874):    ... 36 more

正如你所看到的,没有什么指向我的code;我跟踪问题降到此方法的第一行:

As you can see, there is nothing pointing to my code; I tracked the issue down to the first line of this method:

public class NewsDetailActivity extends SherlockFragmentActivity{
   .
   .
   .
   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       getSupportMenuInflater().inflate(R.menu.news_detail, menu);
       //mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share).getActionProvider();
       //mShareActionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
       return super.onCreateOptionsMenu(menu);
   }

如果该行被删除,该活动的工作就好了。菜单布局如下所示:

If that line is removed, the activity works just fine. The menu layout is shown below:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
    android:id="@+id/share"
    android:title="@string/share"
    android:showAsAction="ifRoom"
    android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"/>
</menu>

我一直无法得到解决的问题,一直没能找到有人用类似的问题。不过,我没有在图书馆阅读的维基主题可能是问题,以下是主题为我的应用程序和动作条,我把它改成Theme.Sherlock.Light和其他许多人都没有用。

I have been unable to resolved the issue and haven't been able to find someone with a similar issue. However, I did read in the library's wiki that Themes might be the problem, the following is the theme for my app and actionbar, I have changed it to Theme.Sherlock.Light and many others to no avail.

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="Theme.Sherlock">
    <item name="actionBarStyle">@style/ActionBar</item>
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="@style/Widget.Sherlock.ActionBar">
    <item name="android:textColor">#ffffff</item>
    <item name="android:textStyle">bold</item>>
    <item name="android:background">@drawable/background_actionbar</item>
    <item name="android:backgroundStacked">@drawable/background_actionbar</item>
    <item name="android:backgroundSplit">@drawable/background_actionbar</item>
</style>
</resources>

我使用该库的最新版本。我希望有人可以帮助我!谢谢!

I am using the latest version of the library. I hope someone could help me out! Thanks!

编辑:我一直没能解决的问题,但我在ActionBarSherlock(布局/ abs_activity_chooser_view.xml)跟踪异常下降到这个XML:

I haven't been able to solve the problem, but I tracked the Exception down to this XML in ActionBarSherlock (layout/abs_activity_chooser_view.xml):

<com.actionbarsherlock.internal.widget.IcsLinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/abs__activity_chooser_view_content"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    style="?attr/activityChooserViewStyle">

    <FrameLayout
        android:id="@+id/abs__expand_activities_button"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:focusable="true"
        android:addStatesFromChildren="true"
        android:background="?attr/actionBarItemBackground">

        <ImageView android:id="@+id/abs__image"
            android:layout_width="56dip"
            android:layout_height="36dip"
            android:layout_gravity="center"
            android:paddingTop="2dip"
            android:paddingBottom="2dip"
            android:paddingLeft="12dip"
            android:paddingRight="12dip"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true" />

    </FrameLayout>

    <FrameLayout
        android:id="@+id/abs__default_activity_button"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:focusable="true"
        android:addStatesFromChildren="true"
        android:background="?attr/actionBarItemBackground">

        <ImageView android:id="@+id/abs__image"
            android:layout_width="56dip"
            android:layout_height="36dip"
            android:layout_gravity="center"
            android:paddingTop="2dip"
            android:paddingBottom="2dip"
            android:paddingLeft="12dip"
            android:paddingRight="12dip"
            android:scaleType="fitCenter"
            android:adjustViewBounds="true" />

    </FrameLayout>

</com.actionbarsherlock.internal.widget.IcsLinearLayout>

这似乎是异常引起的FrameLayout。

It seems like the exception is caused by the FrameLayout.

编辑2:确定,我已经找到一种方法来崩溃停止的应用程序。我删除从我的应用程序,并从动作条的风格的自定义主题,使应用程序的主题,如:

EDIT 2: Ok, I have found a way to stop the app from crashing. I removed the custom theme from my app and the style from the actionbar, leaving the app theme like:

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

这工作得很好,但是,我已经失去了定制的可能性动作条

This works well, however, I have lost the possibility of customizing the actionbar.

推荐答案

更改您的活动风格,安卓主题=@风格/ Theme.Sherlock在AndroidManifest.xml

Change style of your activity to android:theme="@style/Theme.Sherlock" in the AndroidManifest.xml

像这样

    <activity
        android:name=".MainActivity"
        android:theme="@style/Theme.Sherlock">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

这篇关于ActionBarSherlock和放大器; ShareActionProvider引起InflateException(找到原因,解决不了)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆