The line 'listener2.applyTexts2(infor);' gives me an error that I pass a null object reference on applyTexts2. I debugged this line and 'infor' has all values passed to it normally, yet it still says that it is null. What did I do wrong?
(I am calling this from my MainActivity from a button and the popup to insert the info is fine, everything looks good, yet it says about null when I have no null in the data. I have another listener in my MainActivity and it works fine. Does the first one somehow mess the second one? They are completely separate classes)
public class StaffDialog extends AppCompatDialogFragment{
private StaffDialogListener listener2;
private EditText FirstName;
private EditText LastName;
private EditText Phone;
private EditText Linkedin;
private EditText Tran;
private String[] infor = new String[5];
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.layout_dialog2,null);
builder.setView(view)
.setTitle("Enter this person's information")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
infor[0]=FirstName.getText().toString();
infor[1]=LastName.getText().toString();
infor[2]=Phone.getText().toString();
infor[3]=Linkedin.getText().toString();
infor[4]=Tran.getText().toString();
listener2.applyTexts2(infor);
}
});
FirstName = view.findViewById(R.id.name);
LastName = view.findViewById(R.id.lastname);
Phone = view.findViewById(R.id.phone);
Linkedin = view.findViewById(R.id.linkedin);
Tran = view.findViewById(R.id.tran);
return builder.create();
}
@Override
public void onAttach(Context context){
super.onAttach(context);
try{
listener2 = (StaffDialogListener) context;
}catch(Exception e){
e.printStackTrace();
}
}
public interface StaffDialogListener{
void applyTexts2(String[] info);
}
}```