【发布时间】:2017-10-20 02:40:42
【问题描述】:
我完全是 Android Studio 的新手。
我刚刚在 Windows 10 上安装了它,因为我想学习如何使用它,所以我开始遵循在线指南 (https://developer.android.com/training/basics/firstapp/starting-activity.html#Up)。
我确实是一步一步地跟着它,但是当涉及到这部分代码时:
public class DisplayMessageActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
// Get the Intent that started this activity and extract the string
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Capture the layout's TextView and set the string as its text
TextView textView = (TextView) findViewById(R.id.textView);
textView.setText(message);
}
“findViewById”之后的“textView”部分显示为红色,我收到以下错误消息:“无法解析符号'textView'”。
即使我已导入 android.widget.TextView,也会发生这种情况。
也许这是个愚蠢的问题,但我对 Android Studio 完全陌生。 感谢您的回答:)
【问题讨论】:
-
您可以将
activity_display_message.xml的内容添加到您的问题中吗?