1

我一直在关注它,我被困在 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();

`

4

2 回答 2

3

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

TextView textView = new TextView(this); // Change the "v" to uppercase
textView.setTextSize(40);
textView.setText(message);
于 2013-07-22T19:08:17.617 回答
0

Java 中的变量区分大小写,因此textViewtextview是不同的。将您的代码更改为:

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

// Set the text view as the activity layout
setContentView(textview);
于 2013-07-22T19:07:47.380 回答