我使用android.support.v7.widget.ShareActionProvider支持较旧的设备,但是每当我运行应用程序时,都找不到类,这是日志猫

07-27 16:32:19.954:W / SupportMenuInflater(16559):无法实例化类:anroid.support.v7.widget.ShareActionProvidor
    07-27 16:32:19.954:W / SupportMenuInflater(16559):java.lang.ClassNotFoundException:在路径:DexPathList [[zip file“ / data / app / com.example.sunshine-2.apk“],nativeLibraryDirectories = [/ data / app-lib / com.example.sunshine-2,/ system / lib]]
    07-27 16:32:19.954:W / SupportMenuInflater(16559):在dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.internal.view.SupportMenuInflater $ MenuState.newInstance(SupportMenuInflater.java:480)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.internal.view.SupportMenuInflater $ MenuState.readItem(SupportMenuInflater.java:383)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.internal.view.SupportMenuInflater.parseMenu(SupportMenuInflater.java:168)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.internal.view.SupportMenuInflater.inflate(SupportMenuInflater.java:118)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at com.example.sunshine.DetailActivity $ DetailFragment.onCreateOptionsMenu(DetailActivity.java:68)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1586)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1973)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:226)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.app.ActionBarActivity.superOnCreatePanelMenu(ActionBarActivity.java:233)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.app.ActionBarActivityDelegateICS.onCreatePanelMenu(ActionBarActivityDelegateICS.java:146)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.support.v7.app.ActionBarActivity.onCreatePanelMenu(ActionBarActivity.java:200)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):在android.support.v7.app.ActionBarActivityDelegateICS $ WindowCallbackWrapper.onCreatePanelMenu(ActionBarActivityDelegateICS.java:293)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:436)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于com.android.internal.policy.impl.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:800)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at com.android.internal.policy.impl.PhoneWindow $ 1.run(PhoneWindow.java:221)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.os.Handler.handleCallback(Handler.java:733)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.os.Handler.dispatchMessage(Handler.java:95)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.os.Looper.loop(Looper.java:136)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):位于android.app.ActivityThread.main(ActivityThread.java:5017)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at java.lang.reflect.Method.invokeNative(本机方法)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at java.lang.reflect.Method.invoke(Method.java:515)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    07-27 16:32:19.954:W / SupportMenuInflater(16559):在dalvik.system.NativeStart.main(本机方法)

这是一个代码

private String data;

        public DetailFragment() {
            setHasOptionsMenu(true);
        }

        @Override
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            // Inflate the menu; this adds items to the action bar if it is present.
            inflater.inflate(R.menu.detailfragment, menu);

            // Retrieve the share menu item
            MenuItem menuItem = menu.findItem(R.id.action_share);

            // Get the provider and hold onto it to set/change the share intent.
            ShareActionProvider mShareActionProvider =
                    (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);

            // Attach an intent to this ShareActionProvider.  You can update this at any time,
            // like when the user selects a new piece of data they might like to share.
            if (mShareActionProvider != null ) {
                mShareActionProvider.setShareIntent(createShareForecastIntent());
            } else {
                Log.d("SAP", "Share Action Provider is null?");
            }
        }

        private Intent createShareForecastIntent() {
            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            shareIntent.setType("text/plain");
            shareIntent.putExtra(Intent.EXTRA_TEXT,
                    data + "#Sunshine");
            return shareIntent;
        }

最佳答案

如果完全存在,则必须为android.support.v7.widget.ShareActionProvider

您似乎在xml中或其名称中拼错了名称。

关于android - 无法实例化类:anroid.support.v7.widget.ShareActionProvidor,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24985526/

10-10 02:13