DisplayMessageActivity.java上的MyFirstApp android教程错误

时间:2013-07-22 19:04:58

标签: android textview

我一直在关注它,我遇到了3个textview错误 教程:http://developer.android.com/training/basics/firstapp/starting-activity.html 我得到2错误,说textView无法解析,有人说textView无法解析为变量。帮助!

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the message from the intent
    Intent intent = getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    // Create the text view
    TextView textview = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    // Set the text view as the activity layout
    setContentView(textView);

    setContentView(R.layout.activity_display_message);
    // Show the Up button in the action bar.
    setupActionBar();

`

2 个答案:

答案 0 :(得分:3)

您已将其声明为textview(小写“v”),但将其引用为textView(大写“v”)。选一个!

TextView textView = new TextView(this); // Change the "v" to uppercase
textView.setTextSize(40);
textView.setText(message);

答案 1 :(得分:0)

Variables in Java are case sensitive,因此textViewtextview不同。将您的代码更改为:

TextView textview = new TextView(this);
textview.setTextSize(40);
textview.setText(message);

// Set the text view as the activity layout
setContentView(textview);