The problem is similar to this SO post.
@Jason replies that -
Your Fragment hasn't attached to the Activity yet, which also means your layout hasn't been inflated yet.
In that case, the issue was to simply pass the string from one fragment to another.
However, here I need to do something different:
Common.java
public class Common extends Fragment
{
OnSelectedListener mCallback = new OnSelectedListener(){
public void getFailureDialog(){
RecordFailure fd = new RecordFailure();
fd.show(getActivity().getSupportFragmentManager(), "dialog"); //Null pointer exception here.
}
};
I call mCallback.getFailureDialog()
to call that method.
Error Log:
03-22 18:21:30.022: E/AndroidRuntime(9385): java.lang.NullPointerException
03-22 18:21:30.022: E/AndroidRuntime(9385): at com.cornmain.util.Common$1.getFailureDialog(Common.java:112)
How to do that?
UPDATE:
If I use fd.show(getFragmentManager(), "dialog");
, then I get the following error:
Error Log:
03-22 18:35:18.432: E/AndroidRuntime(11872): java.lang.NullPointerException
03-22 18:35:18.432: E/AndroidRuntime(11872): at android.support.v4.app.DialogFragment.show(DialogFragment.java:125)
03-22 18:35:18.432: E/AndroidRuntime(11872): at com.cornmain.util.Common$1.getFailureDialog(Common.java:112)