0





41

Advertisement

I am trying to implement ShareActionProvider but getting :

02-20 04:14:28.894: E/AndroidRuntime(1145): Process: com.learn2crack.tab, PID: 1145
02-20 04:14:28.894: E/AndroidRuntime(1145): java.lang.ClassCastException: android.support.v7.widget.ShareActionProvider cannot be cast to android.view.ActionProvider

menu.xml:

  <item
    android:id="@+id/share"
    android:title="@string/share"
    android:actionProviderClass="android.support.v7.widget.ShareActionProvider"
    android:showAsAction="always" />

I imported this to my class:

    import android.support.v7.widget.ShareActionProvider;

complete Log:

02-20 04:14:28.894: E/AndroidRuntime(1145): FATAL EXCEPTION: main
02-20 04:14:28.894: E/AndroidRuntime(1145): Process: com.learn2crack.tab, PID: 1145
02-20 04:14:28.894: E/AndroidRuntime(1145): java.lang.ClassCastException: android.support.v7.widget.ShareActionProvider cannot be cast to android.view.ActionProvider
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.MenuInflater$MenuState.readItem(MenuInflater.java:374)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.MenuInflater.parseMenu(MenuInflater.java:160)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.MenuInflater.inflate(MenuInflater.java:110)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at com.learn2crack.tab.MainActivity.onCreateOptionsMenu(MainActivity.java:72)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.app.Activity.onCreatePanelMenu(Activity.java:2538)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:224)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:221)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.Choreographer.doFrame(Choreographer.java:543)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.os.Handler.handleCallback(Handler.java:733)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.os.Handler.dispatchMessage(Handler.java:95)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.os.Looper.loop(Looper.java:136)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at android.app.ActivityThread.main(ActivityThread.java:5017)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at java.lang.reflect.Method.invoke(Method.java:515)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-20 04:14:28.894: E/AndroidRuntime(1145):     at dalvik.system.NativeStart.main(Native Method)
Question author Sun | Source

Advertisement


0


Change to

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

Check the topic Using the ShareActionProvider

http://developer.android.com/guide/topics/ui/actionbar.html

Answer author Raghunandan