I'm a begginer with Android and currently stuck with the lession: http://developer.android.com/training/basics/firstapp/starting-activity.html
In the part Create the Second Activity, when I try to use the code:
public class DisplayMessageActivity extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
I get the error below:
@SuppressLint("NewApi") -> The attribute value is undefined for the annotation type SuppressLint.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) -> HONEYCOMB cannot be resolved or is not a field.
getActionBar().setDisplayHomeAsUpEnabled(true); -> The method getActionBar() is undefined for the type DisplayMessageActivity.
NavUtils.navigateUpFromSameTask(this); -> NavUtils cannot be resolved
Someone let me know how to solve? Here is what I imported:
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
Many thanks!
SuppressLint
annotation was added in API level 16. You need to either:
tools/support/annotations.jar
from your Android SDK to the project libs
.import android.annotation.SuppressLint;
I ran into the exact same problem. CTRL-SHIFT-o (organize imports) filled in the missing import for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With