I have a string in Activity A that should be passed to Activity B and displayed in a TextView.
This is the code in Activity A:
- Code: Select all
String sToSend = "pass this string...";
Intent i = new Intent(this, ActivityB.class);
i.putExtra("justTesting", sToSend);
startActivity(i);
And this is the code in Activity B (a button is pressed (this code is in the onClick() of the button), then the TextView should display the string from the first Activity):
- Code: Select all
try
{
//getting String from other Activity
Intent i = getIntent();
String sGetIt = iTestIntent.getExtras().getString("justTesting");
tvDisplayString.setText("tvOffsetValueFromOtherActivity: "+sGetIt);
}
catch (Exception e)
{
e.printStackTrace();
Toast ng = Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT);
ng.show();
}
I get a NullPointerException at the line that says "String sGetIt=...".
Thanks in advance,
Marbert


), but it just displays 'null' for sGetIt.
