我正在尝试按照本教程:http://developer.android.com/guide/topics/ui/controls/pickers.html#DatePicker
这是他们提供的代码,所以我创建了一个新类。但是我在新班上遇到错误。我在定义public static class DatePickerFragment
时遇到错误。错误为Illegal modifier for the class DatePickerFragment; only public, abstract & final are permitted
public static class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
}
}
答案 0 :(得分:1)
我猜你在单独的.java文件中有代码。摆脱static
关键字。
如果它是一个内部类,那么你可以在Activity类中使用静态修饰符。
同时检查一下顶级课程不能是静态的
Illegal modifier error for static class
你可以找到一个例子@
How to transfer the formatted date string from my DatePickerFragment?