在编写完代码在虚拟机运行之后,点击按钮出现闪退
点击按钮后如下:
显示效果应该是
运行过程并未报错,自己感觉.java文件只能运行一个,另一个没有运行成功,MainActivity.java文件如下
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText et_password;
private Button btn_send;
private EditText et_name;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.muser);
et_name=(EditText) findViewById(R.id.et_name);
et_password=(EditText) findViewById(R.id.et_password);
btn_send=(Button) findViewById(R.id.btn_send);
btn_send.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
passDate();
}
});
}
public void passDate(){
Intent intent=new Intent(MainActivity.this,ShowActivity.class);
intent.putExtra("name",et_name.getText().toString().trim());
intent.putExtra("password",et_password.getText().toString().trim());
startActivity(intent);
}
}
ShowActivity.java文件如下
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class ShowActivity extends AppCompatActivity {
private TextView tv_name;
private TextView tv_password;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
Intent intent=getIntent();
String name=intent.getStringExtra("name");
String password=intent.getStringExtra("password");
tv_name=(TextView) findViewById(R.id.tv_name);
tv_password=(TextView) findViewById(R.id.tv_password);
tv_name.setText("用户名:"+name);
tv_password.setText("密 码:"+password);
}
}
求解决方法。