java - 无法解析方法“newInstance”
问题描述
我收到以下错误:
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");
}
解决方案
如果我错了,请原谅我。我不熟悉这些观点。但是,我认为您应该使用:
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
我猜您从某个库(扩展了 a )中复制了代码。这就是为什么你有一些冲突。
为了使您的代码使用这些的默认实现工作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();
}
推荐阅读
- c++ - 在 C++ 中使用库“xtensor-blas”时出错
- reactjs - 为什么 router.push 使用 next.js 重新加载/重新渲染页面?
- c# - 在 SQL Server 数据库中管理 SAAS 应用程序的用户
- vba - 从一个文档复制选定的文本并粘贴到页面上相同位置的新文档
- python - Python3 Tarfile: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf0 in position
- javascript - 从 mapbox 中检索没有地图的地理编码器的值
- java - 如何让程序检查数组 arr 的每个元素是否是同一数组的其他元素的倍数?
- dom - Embarcadero C++ 10.1 x64 中的 Try-catch 问题
- ios - *当前*正在触摸哪个 SwiftUI 节点?
- javascript - 为什么用`console.log`调用对象时会记录`[object Object]`?