坚持@燮pressLint(" NewApi")(developer.android.com/training/basics/firstapp/starting-activity)

2023-09-07 03:13:59 作者:天煞之星

我和Android的一个初学者,目前套牢lession:http://developer.android.com/training/basics/firstapp/starting-activity.html

I'm a begginer with Android and currently stuck with the lession: http://developer.android.com/training/basics/firstapp/starting-activity.html

在部分创建第二个活动,当我尝试使用code:

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:

@燮pressLint(NewApi) - >属性值是不确定的注释类型燮pressLint

@SuppressLint("NewApi") -> The attribute value is undefined for the annotation type SuppressLint.

如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS 蜂窝。) - >蜂窝不能得到解决,或者不是一个领域

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) -> HONEYCOMB cannot be resolved or is not a field.

getActionBar ()setDisplayHomeAsUpEnabled(真)。 - >该方法getActionBar()是未定义的类型DisplayMessageActivity

getActionBar().setDisplayHomeAsUpEnabled(true); -> The method getActionBar() is undefined for the type DisplayMessageActivity.

NavUtils .navigateUpFromSameTask(本); - > NavUtils解决不了

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;

非常感谢!

推荐答案

您生成目标未设置为API级别14或更高。这是不是一个错误,请关闭这个问题。

Your build target is NOT set to API Level 14 or higher. This is not a bug, please close this issue.

(在Eclipse:项目=>属性=>安卓)