Je dois passer une chaîne créée de 'Activité A' à 'Activité B' afin que je puisse l'afficher dans un TextView. Le problème est que le code provoque Android ne répond pas, son identique aux autres tutoriels en ligne.Android .putExtra (ne répond pas)
Merci pour vos commentaires.
Activité A.onCreate()
check_button = (Button) findViewById(R.id.check_button);
check_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent i = new Intent(AddActivity.this, DetailActivity.class);
String hash = text_hash.toString();
i.putExtra("hash" , hash);
startActivity(i);
}
});
Activité B.onCreate()
Bundle extras = getIntent().getExtras();
if (extras != null)
{
passedHash = (String) getIntent().getExtras().getString("hash");
hash.setText(passedHash);
}
pile trace:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
text_hash a textView? –
Oui, voir la modification à la question :) – EightSquared
Comme @SajedulKarim a dit que vous devriez utiliser Chaîne hash = text_hash.getText(). ToString(); –