Reputation: 41
In this app, I want to test how to send data between activities
. This is the code that I used:
public class MainActivity extends AppCompatActivity {
EditText parola,email;
Button buton;
@Override
protected void onCreate(Bundle savedInstanceState) {
parola.findViewById(R.id.enterPassword);
email.findViewById(R.id.enterMail);
buton.findViewById(R.id.button);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String StrEmail=email.getText().toString();
String StrParola=parola.getText().toString();
buton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),ActivityB.class);
i.putExtra("mail",StrEmail);
i.putExtra("pass",StrParola);
startActivity(i);
}
});
}
}
But every time I open the app, it just crashes.
Upvotes: 0
Views: 38
Reputation: 316
You forgot to add =
before intiliasing the Editext
and Button
public class MainActivity extends AppCompatActivity {
EditText parola,email;
Button buton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
parola = findViewById(R.id.enterPassword); // forgot =
email = findViewById(R.id.enterMail);
buton = findViewById(R.id.button);
String StrEmail=email.getText().toString();
String StrParola=parola.getText().toString();
buton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(getApplicationContext(),ActivityB.class);
i.putExtra("mail",StrEmail);
i.putExtra("pass",StrParola);
startActivity(i);
}
});
}
}
Upvotes: 1