4

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)
4

1 に答える 1

3
  android:icon="@+id/ic_action_share"

これは間違っています。ドローアブルを割り当てているのではなく、R.java クラスに Id を追加しているだけです。次のように、ここでアイコンを参照する必要があります。

   android:icon="@drawable/ic_action_share"
于 2013-01-24T02:12:44.547 に答える