MyFirstApp教程Android Studio在應用程序中接收消息的問題。MyFirstApp教程Android Studio 2.3構建錯誤EXTRA_MESSAGE和textview
生成錯誤如下:
Error:(17, 60) error: cannot find symbol variable EXTRA_MESSAGE
Error:(20, 57) error: cannot find symbol variable textView
我的消息接收器的代碼如下所示:
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);
}
注:EXTRA_MESSAGE和TextView的是紅色。
發送代碼如下所示:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user taps the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this,
DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}
注:在此行中我的代碼從上面:
public void sendMessage(View view)
第一個「查看」具有光水平線通過它,我得到類似sendMessage(View視圖)的錯誤消息已折舊。
我認爲這個問題可能涉及
public void sendMessage(View view)
及其折舊碼消息...
鏈接到教程,其中出現問題(?):
https://developer.android.com/training/basics/firstapp/starting-activity.html