gpt4 book ai didi

android - ClasscastException android.support.v7.widget.ShareActionProvider 到 action.view.ActionProvider

转载 作者:太空狗 更新时间:2023-10-29 15:08:40 25 4
gpt4 key购买 nike

<分区>

下面是我的 Activity 代码。

问题是我无法正确使用 AppCompat 库,它给了我

ClasscastException android.support.v7.widget.ShareActionProvider 到 action.View.ActionProvider

   import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.ShareActionProvider;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends ActionBarActivity{
android.support.v7.widget.ShareActionProvider shareAction;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
MenuItem item =(MenuItem) menu.findItem(R.id.menu_settings);
shareAction = (ShareActionProvider) MenuItemCompat
.getActionProvider(item);
shareAction.setShareIntent(createShareIntent());
return true;
}

public Intent createShareIntent() {
Intent share = new Intent(Intent.ACTION_SEND);
share.setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, "TEST")
.setType("text/plain");
return share;
}

}

根据 developer.android.com 上的指南,我正在正确使用该库

下面是我的菜单文件

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:easyshare="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
easyshare:showAsAction="ifRoom"
easyshare:actionProviderClass="android.support.v7.widget.ShareActionProvider"
/>
</menu>

** 编辑的 LogCat 输出 ** 抱歉,之前我遇到了标签中给出的异常,但现在看到我收到了这个错误,并且不知何故无法找到问题

    10-02 02:17:46.566: E/AndroidRuntime(896): FATAL EXCEPTION: main
10-02 02:17:46.566: E/AndroidRuntime(896): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
10-02 02:17:46.566: E/AndroidRuntime(896): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:98)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
10-02 02 :17:46.566: E/AndroidRuntime(896): at net.mobitexter.easyshare.MainActivity.onCreate(MainActivity.java:16)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.Activity.performCreate(Activity.java:4465)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.ActivityThread.access$600(ActivityThread.java:127)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.os.Handler.dispatchMessage(Handler.java:99)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.os.Looper.loop(Looper.java:137)
10-02 02:17:46.566: E/AndroidRuntime(896): at android.app.ActivityThread.main(ActivityThread.java:4448)
10-02 02:17:46.566: E/AndroidRuntime(896): at java.lang.reflect.Method.invokeNative(Native Method)
10-02 02:17:46.566: E/AndroidRuntime(896): at java.lang.reflect.Method.invoke(Method.java:511)
10-02 02:17:46.566: E/AndroidRuntime(896): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
10-02 02:17:46.566: E/AndroidRuntime(896): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
10-02 02:17:46.566: E/AndroidRuntime(896): at dalvik.system.NativeStart.main(Native Method)
10-02 02:18:02.152: I/Process(896): Sending signal. PID: 896 SIG: 9

*查看 list 是否有帮助*下面是我的 list 文件的代码

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.mobitexter.easyshare"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="17" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="net.mobitexter.easyshare.MainActivity"
android:label="@string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

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