Question

I've got an int i

int i = 5;

then I convert it into String str

String str = Integer.toString(i);

then I try to set String str to TextView tvEx

tvEx.setText(str);

And then my program break down. Can you help me?

ExActivity.java ----------

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data == null) {return;}
    Log.d(TAG, "1");
    int i = data.getIntExtra("Days", days);
    Log.d(TAG, "2");
    String str = Integer.toString(i);
    Log.d(TAG, "3");
    tvD.setText(str);
    Log.d(TAG, "4");
}

Logcat said -----------

D/Days﹕ 1

D/Days﹕ 2

D/Days﹕ 3

Virtual device -----------

Sorry, Days has stopped

Était-ce utile?

La solution

Do yourself a favor and specify the exact problem you are having and update the question with an output of your program after it fails.

Try this:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (data != null && data.getExtras().containsKey("Days")) {
        int i = data.getExtras().getIntExtra("Days", days);
        TextView tvD = (TextView) findViewById(R.id.MA_TvDays);
        if (tvD != null) tvD.setText("" + i);
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top