无法解析方法“ newInstance”

时间:2019-07-05 16:59:05

标签: java android

我遇到以下错误:

Cannot resolve method 'newInstance(com.example.ghazalitodo.AddReminderActivity, int, int, boolean)

这是我的代码:

public void setTime(View v) {
    if (mCurrentReminderUri == null) {
        Toast.makeText(this, "click again on the reminder list to set time alarm", Toast.LENGTH_LONG).show();
        return;
    }
    Calendar now = Calendar.getInstance();
    TimePickerDialog tpd = TimePickerDialog.newInstance(this, now.get(Calendar.HOUR_OF_DAY),
            now.get(Calendar.MINUTE), false);
    tpd.setThemeDark(false);
    tpd.show(getFragmentManager(), "Timepickerdialog");
}

// On clicking Date picker
public void setDate(View v) {
    if (mCurrentReminderUri == null) {
        Toast.makeText(this, "click again on the reminder list to set date alarm", Toast.LENGTH_LONG).show();
        return;
    }
    Calendar now = Calendar.getInstance();
    DatePickerDialog dpd = DatePickerDialog.new Instance(this, now.get(Calendar.YEAR),
            now.get(Calendar.MONTH),
            now.get(Calendar.DAY_OF_MONTH)
    );
    dpd.show(getFragmentManager(), "Datepickerdialog");
}

1 个答案:

答案 0 :(得分:0)

请,如果我错了,请原谅我。我不熟悉这些观点。但是,我认为您应该使用:

TimePickerDialog tpd = new TimePickerDialog(this, null, 
        now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), false);

DatePickerDialog dpd = new DatePickerDialog (this, null, now.get(Calendar.YEAR),
        now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH);

让我知道是否有帮助。否则,我将删除答案

编辑

我猜您是从某个库(扩展了DialogFragment)中复制了代码。这就是为什么您遇到一些冲突。

为了使代码能够使用这些Dialog的默认实现来工作,可以使用:

public void setTime(View v) {
    if (mCurrentReminderUri == null) {
        Toast.makeText(this, "click again on the reminder list to set time alarm", Toast.LENGTH_LONG).show();
        return;
    }
    Calendar now = Calendar.getInstance();
    TimePickerDialog tpd = new TimePickerDialog(this, null,
            now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), false);
    tpd.show();
}

// On clicking Date picker
public void setDate(View v) {
    if (mCurrentReminderUri == null) {
        Toast.makeText(this, "click again on the reminder list to set date alarm", Toast.LENGTH_LONG).show();
        return;
    }
    Calendar now = Calendar.getInstance();
    DatePickerDialog dpd = new DatePickerDialog (this, null, now.get(Calendar.YEAR),
            now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
    dpd.show();
}