gpt4 book ai didi

android - ActionBarSherlock ShareActionProvider 问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:04:21 27 4
gpt4 key购买 nike

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

在 Debug模式下,我可以逐步完成的最深入操作是 SherlockFragmentActivity 中的 onCreatePanelMenu()。

主菜单.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;
}
. . .

}

异常(exception):

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)

最佳答案

  android:icon="@+id/ic_action_share"

这是错误的。您没有分配可绘制对象,只是将 Id 添加到 R.java 类中。你需要在这里引用一个图标,像这样:

   android:icon="@drawable/ic_action_share"

关于android - ActionBarSherlock ShareActionProvider 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14492757/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com