为了使我的应用程序兼容到api 2.2,我添加了appcompat_v7
,因为您可以看到我的项目属性
然后我在libs文件夹中添加了android-support-v4.jar
- >然后右击 - >添加到构建路径。
之后,我在Java Build Path
中检查了这些项目我跟随this tutorial到第5点。
所以,在清单中:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="COI: Ministry of Law & Justice"
android:theme="@style/AppTheme" >
<activity
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation"
android:name="com.example.indianconstitution.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
android:theme="@style/Theme.AppCompat" /////I added this line for comaptibility
</activity>
</application>
所以,在main.xml中:
<menu xmlns:yourapp="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:id="@+id/action_settings"
android:orderInCategory="100"
android:showAsAction="never"
yourapp:actionProviderClass="android.support.v7.widget.ShareActionProvider"
android:title="@string/action_settings"/>
</menu>
我的onCreateOptionsMenu
:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem shareItem = menu.findItem(R.id.action_settings);
// Need to use MenuItemCompat to retrieve the Action Provider
mActionProvider = (ActionProvider)
MenuItemCompat.getActionProvider(shareItem);
return super.onCreateOptionsMenu(menu);
}
现在,由于getActionBar
,setDisplayHomeAsUpEnabled
,setHomeButtonEnabled
,setTitle
,invalidateOptionsMenu
等,我的代码中出现了很多错误。所有人都说我在清单中使用API 11。
我完全迷失了我现在该怎么办?
更新在API 2.2中添加@SuppressLint("NewApi")
避免了所有这些错误我收到此错误
Logcat如下:
logcat的:
07-16 10:28:26.282: W/dalvikvm(329): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-16 10:28:26.293: E/AndroidRuntime(329): FATAL EXCEPTION: main
07-16 10:28:26.293: E/AndroidRuntime(329): java.lang.NoSuchMethodError: com.example.indianconstitution.MainActivity.getActionBar
07-16 10:28:26.293: E/AndroidRuntime(329): at com.example.indianconstitution.MainActivity.onCreate(MainActivity.java:54)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.os.Looper.loop(Looper.java:123)
07-16 10:28:26.293: E/AndroidRuntime(329): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-16 10:28:26.293: E/AndroidRuntime(329): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 10:28:26.293: E/AndroidRuntime(329): at java.lang.reflect.Method.invoke(Method.java:521)
07-16 10:28:26.293: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-16 10:28:26.293: E/AndroidRuntime(329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-16 10:28:26.293: E/AndroidRuntime(329): at dalvik.system.NativeStart.main(Native Method)
请帮忙......