ActionBarSherlock ShareActionProvider问题

时间:2013-01-24 02:09:38

标签: android exception actionbarsherlock shareactionprovider

ActionBarSherlock(ABS)是根据最新的来源构建的。我使用ABS ShareActionProvider时抛出异常。我可以通过onCreateOptionsMenu()调试就好了。如果我取出@ + id / menu_item_share的xml,那么apk运行正常。

我可以在调试模式中进入最远的是SherlockFragmentActivity中的onCreatePanelMenu()。

main_menu.xml:

 <item android:id="@+id/menu_item_share"
      android:icon="@+id/ic_action_share"
      android:showAsAction="ifRoom"
      android:title="@string/menu_share"
      android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider" 
 />

相关守则:

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.ShareActionProvider;

public class MyActivity extends SherlockFragmentActivity {

. . . 

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getSupportMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.menu_item_share).getActionProvider();

    if(this.verse.verse != null)
        mShareActionProvider.setShareIntent(getDefaultShareIntent());

    return true;
}

public Intent getDefaultShareIntent(){
    Intent sendIntent = new Intent();
    sendIntent.setAction(Intent.ACTION_SEND);
    sendIntent.putExtra(Intent.EXTRA_TEXT, "text to share");
    sendIntent.setType("text/plain");

    return sendIntent;
}
. . . 

}

例外:

01-23 19:53:38.048: WARN/dalvikvm(14643): threadid=1: thread exiting with uncaught exception (group=0x411d4930) 01-23 19:53:38.048: ERROR/AndroidRuntime(14643): FATAL EXCEPTION: main
        android.content.res.Resources$NotFoundException: Resource ID #0x7f030008
        at android.content.res.Resources.getValue(Resources.java:1014)
        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2166)
        at android.content.res.Resources.getLayout(Resources.java:853)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
        at com.actionbarsherlock.widget.ActivityChooserView.<init>(ActivityChooserView.java:229)
        at com.actionbarsherlock.widget.ActivityChooserView.<init>(ActivityChooserView.java:202)
        at com.actionbarsherlock.widget.ActivityChooserView.<init>(ActivityChooserView.java:192)
        at com.actionbarsherlock.widget.ShareActionProvider.onCreateActionView(ShareActionProvider.java:164)
        at com.actionbarsherlock.internal.view.ActionProviderWrapper.onCreateActionView(ActionProviderWrapper.java:23)
        at android.view.ActionProvider.onCreateActionView(ActionProvider.java:98)
        at com.android.internal.view.menu.MenuItemImpl.getActionView(MenuItemImpl.java:580)
        at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:157)
        at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:455)
        at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1048)
        at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87)
        at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:190)
        at com.android.internal.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:244)
        at com.android.internal.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:946)
        at com.android.internal.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:969)
        at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:450)
        at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:769)
        at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:201)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
        at android.view.Choreographer.doCallbacks(Choreographer.java:562)
        at android.view.Choreographer.doFrame(Choreographer.java:531)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
        at android.os.Handler.handleCallback(Handler.java:725)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5191)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
        at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:3)

  android:icon="@+id/ic_action_share"

这是错误的。你没有分配一个drawable,你只是在你的R.java类中添加一个Id。你需要在这里引用一个图标,如下所示:

   android:icon="@drawable/ic_action_share"