AggieDev
AggieDev

Reputation: 5045

Weird error in Eclipse with Android

This didn't start happening until today but I am wondering what is causing it. Whenever I compile, like one out of every 10 times all of the sudden the same 2 errors show up, pointing to

this.onBackPressed();

and

android:theme="@android:style/Theme.Holo"

both of which give errors along the lines of 'requires API level of 5' or 'requires API level of 16.'

The thing is, the errors go away by clicking Project>>Clean each time, so because it runs fine I do that every time, but it just keeps happening. What could be causing this?

Upvotes: 0

Views: 68

Answers (2)

BinaryMonster
BinaryMonster

Reputation: 63

If the minimum API level (that you set at the beginning of your project) is lower than 5 (the error you are getting), Eclipse will give you an error because any device running API 4 or lower isn't supported for this.onBackPressed();, and devices running API 15 or lower isn't supported for the Holo Theme.

To avoid these errors you can either change the API level of your project to 16, or you could remove android:theme .... Then you could change the API level of your project to 5 because nowadays most devices are Android 2.2, which is API 8.

Upvotes: 0

ianhanniballake
ianhanniballake

Reputation: 199795

These are Lint errors, which warn you if you are using API level features that are higher than your minSdkVersion (set in your AndroidManifest.xml).

For example, onBackPressed was introduced in API level 5. Attempting to call it on an API level 4 or lower device will cause the application to crash.

Of course, your application will work just fine if you run it on a device API level 5 or higher, hence why it appears to always work.

Upvotes: 1

Related Questions