For making my app compatible down to api 2.2, I added appcompat_v7
as you can see my project properties
Then I added android-support-v4.jar
in libs folder -> then right click-> add to build path.
After that I checked these items in Java Build Path
I am following this tutorial upto their 5th point.
So, In manifest:
<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>
So, in 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>
And my 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);
}
Now,I am getting many errors in my code due to getActionBar
,setDisplayHomeAsUpEnabled
,setHomeButtonEnabled
,setTitle
,invalidateOptionsMenu
, etc . All saying me to use API 11 in manifest.
I am completely lost what should I do now?
UPDATE Adding @SuppressLint("NewApi")
avoided all these errors , in API 2.2 I am getting this errors
Logcat is below:
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)
Please help....