我尝试使用我的操作栏,我得到了这个执行
08-08 00:54:08.913: E/AndroidRuntime(18468): FATAL EXCEPTION: main
08-08 00:54:08.913: E/AndroidRuntime(18468): java.lang.ClassCastException: android.support.v7.widget.ShareActionProvider cannot be cast to android.view.ActionProvider
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.MenuInflater$MenuState.readItem(MenuInflater.java:374)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.MenuInflater.parseMenu(MenuInflater.java:160)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.MenuInflater.inflate(MenuInflater.java:110)
08-08 00:54:08.913: E/AndroidRuntime(18468): at com.example.workoutlog.AddWorkOutPage.onCreateOptionsMenu(AddWorkOutPage.java:3190)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.app.Activity.onCreatePanelMenu(Activity.java:2490)
08-08 00:54:08.913: E/AndroidRuntime(18468): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:460)
08-08 00:54:08.913: E/AndroidRuntime(18468): at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:822)
08-08 00:54:08.913: E/AndroidRuntime(18468): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:253)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.Choreographer.doFrame(Choreographer.java:531)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.os.Handler.handleCallback(Handler.java:725)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.os.Handler.dispatchMessage(Handler.java:92)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.os.Looper.loop(Looper.java:137)
08-08 00:54:08.913: E/AndroidRuntime(18468): at android.app.ActivityThread.main(ActivityThread.java:5226)
08-08 00:54:08.913: E/AndroidRuntime(18468): at java.lang.reflect.Method.invokeNative(Native Method)
08-08 00:54:08.913: E/AndroidRuntime(18468): at java.lang.reflect.Method.invoke(Method.java:511)
08-08 00:54:08.913: E/AndroidRuntime(18468): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-08 00:54:08.913: E/AndroidRuntime(18468): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-08 00:54:08.913: E/AndroidRuntime(18468): at dalvik.system.NativeStart.main(Native Method)
我已经阅读了有关此错误及其与我的 java 路径有关的内容。
我尝试了各种解决方案,但仍然出现此错误。
这是我的 java 路径顺序和导出:
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/save_wotkout_ab"
android:title="Add Item"
android:icon="@android:drawable/ic_menu_save"
android:showAsAction="ifRoom"/>
<item android:id="@+id/delete_workout_ab"
android:title="Add Item"
android:icon="@android:drawable/ic_delete"
android:showAsAction="ifRoom"/>
<item android:id="@+id/search_ab"
android:title="Add Item"
android:icon="@android:drawable/ic_menu_search"
android:actionViewClass="android.support.v7.widget.SearchView"
android:showAsAction="ifRoom|collapseActionView"/>
<item
android:id="@+id/action_share"
android:actionProviderClass="android.support.v7.widget.ShareActionProvider"
android:showAsAction="ifRoom"
android:title="share"/>
</menu>
例外情况是:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.add_workout_actionbar, menu);
MenuItem shareItem = menu.findItem(R.id.action_share);
mShareActionProvider = (ShareActionProvider)
MenuItemCompat.getActionProvider(shareItem);
mShareActionProvider.setShareIntent(getDefaultIntent());
return super.onCreateOptionsMenu(menu);
}
我进口的
import android.support.v7.widget.ShareActionProvider;
感谢您的帮助