when i run the app it installs but then crashes, ecplise isnt telling there is anything wrong with my code. i think its a problem with my manifest...
Use getSupportActionBar
available with support library v7 as described here on the 6. Retrieve the Action Bar
section
getSupportActionBar documentation
java.lang.NoSuchMethodError: com.example.secondapp.MainActivity.getActionBar
On your MainActivity class, you call getActionBar()
which is not available to your application.
Your android:minSdkVersion
is set to 8 (API-8), which does not provide getActionBar()
(only since API-11).
You should use ActionBarSherlock for good backward compatibility, or set android:minSdkVersion
but then all devices < API-11 won't be targeted.
I faced this same issue before. I just replace
getActionBar()
with
getSupportActionBar()
You are probably running on a phone that is lower than API 11, which is when the method getActionBar
was introduced. If you need to run on devices lower than API level 11, then you will need to guard against executing those calls that only exist on newer API levels, or else use a compatibility library such as ActionBarSherlock or Action Bar Compatiblity. (See this thread for a discussion of the differences between these two.)
Change the android:minSdkVersion="8"
to android:minSdkVersion="11"
and all the newer API calls that you are making will light up as errors. This will make it easier to locate those parts of your code that need attention.
This is because the getActionBar
is a method of api 11, but you can do this:
if (android.os.Build.VERSION.SDK_INT >= 11)
getActionBar().setDisplayHomeAsUpEnabled(true); //example
and in the activity class add this suppress Lint:
@SuppressLint("NewApi")
For api < 11 you have to use:
getSupportActionBar();
Algo make sure you are using appcompat, add this on build.gradle, the 19.+ should be your project target version.
compile 'com.android.support:appcompat-v7:19.+'
Also if you are using invalidateOptionsMenu() for navigation drawer use this instead:
supportInvalidateOptionsMenu();