我收到错误...
错误:错误:此片段应提供默认构造函数(不带参数的公共构造函数)(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();
如何更改错误信息?
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);
}
答案 0 :(得分:1)
添加一个不带参数的默认构造函数:
public NoteEditDialogFragment() {
this.newNote = true;
}
您的应用程序逻辑取决于您将变量初始化为什么默认值,但由于您在调用newInstance时将newNote设置为true,因此我认为true是合理的默认值。