我正在学习 android 基础教程,并且大部分时间都停留在这个教程上。我用“//”突出显示了错误行。我尝试过各种导入行..以前的搜索似乎说这是导入定义类型错误。
package com.example.myapp3;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
public class DisplayMessageActivity extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_display_message);
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.`enter code here`
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
最佳答案
根据您正在遵循的指南......它指出
Note: If you are using an IDE other than Eclipse, your project does not contain the activity_display_message layout that's requested by setContentView(). That's OK because you will update this method later and won't be using that layout.
所以只要继续...您的代码就会更新。
其他说明
setContentView(R.layout.activity_display_message);
这里您正在尝试设置 Activity 的 View ...并引用不存在的布局...如果您将在 res->layout 文件夹中创建一个名为 activity_display_message.xml
的 xml您的项目的..错误将解决。
关于java - Activity_display_message 无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19385781/