为了账号安全,请及时绑定邮箱和手机立即绑定

无法解析方法“newInstance”

无法解析方法“newInstance”

临摹微笑 2023-03-09 16:52:34
我收到以下错误: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 pickerpublic 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 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

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


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);

如果这有帮助,请告诉我。否则,我会删除我的答案


编辑


我猜你是从某个库(扩展了 a )复制了代码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();

}


查看完整回答
反对 回复 2023-03-09
  • 1 回答
  • 0 关注
  • 150 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号