I have a fragment in a User Activity that opens up a Map Activity to receive some string variables.The fragment Has Already Recieved 2 String Variables from the User Activity using Bundles.
This is my Method for doing such but i keep getting that error :
And this is the error i get that kick me out
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.project_seraphim_disease_tracker, PID: 17049
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null,
request=66738, result=-1, data=Intent { (has extras) }} to activity
{com.example.project_seraphim_disease_tracker/com.example.project_seraphim_diseas
e_tracker.User}: java.lang.NullPointerException: Attempt to invoke virtual method
'void android.widget.EditText.setText(java.lang.CharSequence)' on a null object reference
These are in both Map Activity and the Fragment that's in User Activity
private static final String SEARCHED_ADDRESS = "searched_address";
private static final String SEARCHED_NAME = "searched_address_name";
private LatLng SearchedLocationlatLng;
private String SearchedlocationAddress;
private String SearchedlocationName;
This is the button that called to a Map activity from a fragment which is in User Activity
btnAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),Map.class);
startActivityForResult(intent,IDENTIFIER);
}
});
This is what i used to Receive the Strings
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case (IDENTIFIER) : {
if (resultCode == Map.RESULT_OK) {
SearchedlocationAddress=data.getStringExtra(SEARCHED_ADDRESS);
SearchedlocationName=data.getStringExtra(SEARCHED_NAME);
editTextSearchLocationBar.setText(SearchedlocationName);
}
break;
}
}
}
This is in the Map Activity for passing the strings
btnConfirmAddress.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent resultIntent = new Intent();
resultIntent.putExtra(SEARCHED_NAME,SearchedlocationName);
resultIntent.putExtra(SEARCHED_ADDRESS,SearchedlocationAddress);
setResult(Map.RESULT_OK, resultIntent);
finish();
}