Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MyFirstApp教程Android Studio 2.3生成错误重新显示额外消息和文本视图_Java_Android - Fatal编程技术网

Java MyFirstApp教程Android Studio 2.3生成错误重新显示额外消息和文本视图

Java MyFirstApp教程Android Studio 2.3生成错误重新显示额外消息和文本视图,java,android,Java,Android,MyFirstApp教程Android Studio在应用程序内接收消息时出现问题 生成错误如下所示: 错误:(17,60)错误:找不到符号变量EXTRA_消息 错误:(20,57)错误:找不到符号变量textView 我的消息接收器代码如下所示: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.

MyFirstApp教程Android Studio在应用程序内接收消息时出现问题

生成错误如下所示:

错误:(17,60)错误:找不到符号变量EXTRA_消息
错误:(20,57)错误:找不到符号变量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);
}
    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);
    }
}
注意:额外信息和文本视图为红色

发送代码如下所示:

    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);
}
    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(视图视图)被贬低了

我认为这个问题可能与

public void sendMessage(View view) 
还有它被贬低的代码信息。。。(?)

出现问题的教程链接:


检查MainActivity.java文件中的这一行,因为您的代码缺失

public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

检查MainActivity.java文件中的这一行,代码中缺少

public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

不确定是什么起作用,但玩弄它,让它发挥作用。检查导入语句,添加一到两个与文档匹配的语句。

不确定是什么起作用,但对其进行了处理并使其起作用。检查导入语句,添加一个或两个以匹配文档