-7

i get an error...

Error:Error: This fragment should provide a default constructor (a public constructor with no arguments) (com.jdpm.pmn.perfectmaterialnotes.fragments.NoteEditDialogFragment) [ValidFragment]


public class NoteEditDialogFragment extends DialogFragment implements OnClickListener{




private EditText mTitleText;
private EditText mBodyText;
private Long mRowId = null;
private NotesDbAdapter mDbHelper;
private boolean newNote = true;
private Spinner mCategorySpinner;
private String noteText = "";
private Button mSaveButton;
private Button mCancelButton;


public NoteEditDialogFragment(boolean b) {
    this.newNote = b;
}

public static NoteEditDialogFragment newInstance(boolean b) {
    return new NoteEditDialogFragment(b);
}

public static NoteEditDialogFragment newInstance() {
    return new NoteEditDialogFragment(true);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NO_FRAME, R.style.Theme_Rymatenotes_Dialog);
    mDbHelper = new NotesDbAdapter(this.getActivity());
    mDbHelper.open();

how can i change this that the error message doesn't come?

public NoteEditDialogFragment(boolean b) {
    this.newNote = b;
}

public static NoteEditDialogFragment newInstance(boolean b) {
    return new NoteEditDialogFragment(b);
}

public static NoteEditDialogFragment newInstance() {
    return new NoteEditDialogFragment(true);
}
  • 9
    hmmmm, i don't know, maybe you *should provide a default constructor (a public constructor with no arguments)* ... using constructors with arguments for fragments will kick you in the a** sooner or later ... better use set/getArguments instead ... – Selvin Jan 14 '15 at 01:09
  • Should error reporting be more clearer? – Rohit5k2 Jan 14 '15 at 01:30

1 Answers1

1

Add a default constructor with no arguments:

public NoteEditDialogFragment() {
    this.newNote = true;
}

It's up to your app logic what default value you initialize your variables to, but since you are setting newNote to true when you call newInstance I assume true is a sensible default.

What is a constructor?

samgak
  • 23,944
  • 4
  • 60
  • 82