0

For making my app compatible down to api 2.2, I added appcompat_v7 as you can see my project propertiesenter image description here

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 Pathenter image description here

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 &amp; 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....

Kishan Dhamat
  • 3,746
  • 2
  • 26
  • 36
Vivek Warde
  • 1,936
  • 8
  • 47
  • 77
  • Not in logcat , i got errors in my compiler, after implemnting what I stated above – Vivek Warde Jul 16 '14 at 04:44
  • 1
    you should be using the support versions of the methods, eg getSupportActionBar() – panini Jul 16 '14 at 04:45
  • It doesn't recognizes getSupportActionBar() :The method getSupportActionBar() is undefined for the type MainActivity – Vivek Warde Jul 16 '14 at 04:47
  • `MainActivity` needs to `extends ActionBarActivity`. – Mike M. Jul 16 '14 at 05:00
  • Ya, i tried, it doesn't recognize ActionBarActivity too ! `ActionBarActivity cannot be resolved to a type` – Vivek Warde Jul 16 '14 at 05:03
  • please goto this link http://stackoverflow.com/a/8128309/3778703 it's may help you. – Mr X Jul 16 '14 at 05:09
  • `ActionBarActivity` needs to be imported from the support package. – Mike M. Jul 16 '14 at 05:10
  • Ya I tried Ctrl+shift+o but no help – Vivek Warde Jul 16 '14 at 05:14
  • Try manually adding `import android.support.v7.app.ActionBarActivity;`. If that still gives you errors, then the support package isn't being added correctly. – Mike M. Jul 16 '14 at 05:34
  • The import android.support.v7.app cannot be resolved – Vivek Warde Jul 16 '14 at 05:35
  • appcompat & v4 library cannot be used both in the same project, I managed to remove v4 library, then extended ActionBarActivity, & then changed all the instances of `getActionBar()` to `getSupportActionBar()`. After that I am facing this problem http://stackoverflow.com/questions/24777591/java-lang-noclassdeffounderror-android-compatability-issue-in-2-2 – Vivek Warde Jul 16 '14 at 12:58

0 Answers0