I have a custom listView row which looks like this:
I have a customAdapter with the following getView method (not interesting parts were deleted)
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
holder.viewProfileImageButton = view.findViewById(R.id.viewProfileImageButton);
holder.viewProfileImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String pubKey ((objClass_foundUsers)foundUsersList.get(i)).getPublicKey();
Intent getToUserProfileIntent = new Intent(context,activity_1_3_my_profile.class);
context.startActivity(getToUserProfileIntent);
}
});
}
When the user clicks on the first imagebutton in the row this user's profile should be displayed. In order to do this I get the publicKey of the user in the onClick
method in my customAdapter
and want to pass it to another activity
.
When using
getToUserProfileIntent.putExtra("pubKey", pubKey);
in the onClick method in the customAdapter and
pubKey = getIntent().getExtras().getString("pubKey");
in my activity it throws a NullPointerException saying:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.os.Bundle.getString(java.lang.String)' on a null object reference
How can I send the publicKey from this adapter to another activity?