我该怎么做才能将日期发送到光标?
How can I do for send date to cursor?
我无法通过光标获取日期,我测试了所有可能性,但找不到解决方案。
我都试过了。
问题是我想要获取 KEY_DATE_TREATMENT
的第 4 行
public List<Treatment> getTreatmentsList(){
List<Treatment> tList = new ArrayList<>();
Cursor c = getTreatments();
if (c.moveToFirst())
{
do {
SimpleDateFormat dateFormatprev = new SimpleDateFormat("yyyy-MM-dd");
Date d = new Date();
try {
d = dateFormatprev.parse(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
}
catch (ParseException e){
}
Treatment data = new Treatment(c.getInt(c.getColumnIndex(KEY_ID_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDPARCEL_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDTREATMENTPRODUCT_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDWEATHER_TREATMENT)),
c.getString(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
tList.add(data);
}
while (c.moveToNext());
}
c.close();
}
我目前的错误是:
getString(int) in Cursor cannot be applied to Java.lang.String
您对 getString()
进行了额外的不必要且错误的调用:
c.getString(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)))
更改为:
Treatment data = new Treatment(c.getInt(c.getColumnIndex(KEY_ID_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDPARCEL_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDTREATMENTPRODUCT_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDWEATHER_TREATMENT)),
c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
通过更改修复:-
c.getString(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
收件人:-
c.getString(c.getColumnIndex(KEY_DATE_TREATMENT));
您尝试将 c.getString()
与 String 参数一起使用,而不是 int 参数,因为您将 c.getString(c.getColumnIndex(KEY_DATE_TREATMENT))
作为参数。 arg return String(你想要获取的数据)不是整数.
Link 说:-
getString
public abstract String getString (int columnIndex)
Parameters
columnIndex int: the zero-based index of the target column.
c.getColumnIndex(KEY_DATE_TREATMENT)
得到一个 int,值为 name 的列的列偏移量 KEY_DATE_TREATMENT 并在 getString
方法中工作(就像其他使用 getInt
[=41 的行一样=]).
我无法通过光标获取日期,我测试了所有可能性,但找不到解决方案。
我都试过了。
问题是我想要获取 KEY_DATE_TREATMENT
public List<Treatment> getTreatmentsList(){
List<Treatment> tList = new ArrayList<>();
Cursor c = getTreatments();
if (c.moveToFirst())
{
do {
SimpleDateFormat dateFormatprev = new SimpleDateFormat("yyyy-MM-dd");
Date d = new Date();
try {
d = dateFormatprev.parse(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
}
catch (ParseException e){
}
Treatment data = new Treatment(c.getInt(c.getColumnIndex(KEY_ID_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDPARCEL_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDTREATMENTPRODUCT_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDWEATHER_TREATMENT)),
c.getString(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
tList.add(data);
}
while (c.moveToNext());
}
c.close();
}
我目前的错误是:
getString(int) in Cursor cannot be applied to Java.lang.String
您对 getString()
进行了额外的不必要且错误的调用:
c.getString(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)))
更改为:
Treatment data = new Treatment(c.getInt(c.getColumnIndex(KEY_ID_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDPARCEL_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDTREATMENTPRODUCT_TREATMENT)),
c.getInt(c.getColumnIndex(KEY_IDWEATHER_TREATMENT)),
c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
通过更改修复:-
c.getString(c.getString(c.getColumnIndex(KEY_DATE_TREATMENT)));
收件人:-
c.getString(c.getColumnIndex(KEY_DATE_TREATMENT));
您尝试将 c.getString()
与 String 参数一起使用,而不是 int 参数,因为您将 c.getString(c.getColumnIndex(KEY_DATE_TREATMENT))
作为参数。 arg return String(你想要获取的数据)不是整数.
Link 说:-
getString
public abstract String getString (int columnIndex)
Parameters
columnIndex int: the zero-based index of the target column.
c.getColumnIndex(KEY_DATE_TREATMENT)
得到一个 int,值为 name 的列的列偏移量 KEY_DATE_TREATMENT 并在 getString
方法中工作(就像其他使用 getInt
[=41 的行一样=]).