java中无法解析字符串_Android:无法解析方法" query(java.lang.string)" (Android: cannot resolve method "query(java.l...

该博客讨论了一个Android应用中SQLite数据库的问题,开发者试图查询与当前日期和时间匹配的记录,但遇到了'Cannot resolve method'错误。问题出现在尝试使用不正确的SQL查询语句来匹配日期和时间。解决方案可能涉及调整查询以正确比较日期和时间字段。
摘要由CSDN通过智能技术生成

2015-05-04 16:51:40

0

Hey I am trying to query my database for the number of records which match the current date and also match the current time in the same record, however, I am getting a "Cannot resolve method "query(java.lang.string)"

What I need the query to do is check if a records date, and time match the current date and time.

Here is my DatabaseHandler class file

public class DatabaseHandler extends SQLiteOpenHelper{

private static final int DATABASE_VERSION = 1;

private static final String DATABASE_NAME = "FoodTekTrakr",

DATABASE_TABLE = "AlarmManager",

KEY_ID = "id",

KEY_TITLE = "title",

KEY_DATE = "date",

KEY_TIME = "time",

KEY_SONG = "song";

public DatabaseHandler(Context context) {

super(context, DATABASE_NAME, null, DATABASE_VERSION);

}

@Override

public void onCreate(SQLiteDatabase db){

db.execSQL("CREATE TABLE " + DATABASE_TABLE + "(" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + KEY_TITLE + " TEXT," + KEY_DATE + " TEXT," + KEY_TIME + " TEXT," + KEY_SONG + " TEXT)");

}

@Override

public void onUpgrade(SQLiteDatabase db,int oldVersion, int newVersion) {

db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);

onCreate(db);

}

public void createAlarm(UserInputAlarmData AlarmData){

SQLiteDatabase db = getWritableDatabase();

ContentValues values = new ContentValues();

values.put(KEY_TITLE, AlarmData.getTitle());

values.put(KEY_DATE, AlarmData.getDate());

values.put(KEY_TIME, AlarmData.getTime());

values.put(KEY_SONG, AlarmData.getSong());

db.insert(DATABASE_TABLE, null, values);

db.close();

}

public UserInputAlarmData getAlarmData(int id){

SQLiteDatabase db = getReadableDatabase();

Cursor cursor = db.query(DATABASE_TABLE, new String[] {KEY_ID, KEY_TITLE, KEY_DATE, KEY_TIME, KEY_SONG}, KEY_ID

+ "=?", new String[] {String.valueOf(id) }, null, null, null );

if (cursor != null)

cursor.moveToFirst();

UserInputAlarmData AlarmData = new UserInputAlarmData(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));

db.close();

cursor.close();

return AlarmData;

}

public void deleteAlarm(UserInputAlarmData AlarmData){

SQLiteDatabase db = getWritableDatabase();

db.delete(DATABASE_TABLE, KEY_ID + "=?", new String[] { String.valueOf(AlarmData.getId()) });

db.close();

}

public int getAlarmDataCount() {

SQLiteDatabase db =getReadableDatabase();

Cursor cursor = db.rawQuery("SELECT * FROM " + DATABASE_TABLE, null);

int count = cursor.getCount();

db.close();

cursor.close();

return count;

}

public int updateAlarmData(UserInputAlarmData AlarmData){

SQLiteDatabase db = getWritableDatabase();

ContentValues values = new ContentValues();

values.put(KEY_TITLE, AlarmData.getTitle());

values.put(KEY_DATE, AlarmData.getDate());

values.put(KEY_TIME, AlarmData.getTime());

values.put(KEY_SONG, AlarmData.getSong());

return db.update(DATABASE_TABLE, values, KEY_ID + "=?", new String[] { String.valueOf(AlarmData.getId())});

}

public List getAllAlarmData() {

List AlarmDatas = new ArrayList();

SQLiteDatabase db = getWritableDatabase();

Cursor cursor = db.rawQuery("SELECT * FROM " + DATABASE_TABLE, null);

if (cursor.moveToFirst()) {

do {

UserInputAlarmData AlarmData = new UserInputAlarmData(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4));

AlarmDatas.add(AlarmData);

}

while (cursor.moveToNext());

}

return AlarmDatas;

}

public boolean DateAndTimeChecker() {

Date ThisDate = Calendar.getInstance().getTime();

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

String DateChecker = formatter.format(ThisDate);

Date ThisTime = Calendar.getInstance().getTime();

SimpleDateFormat timeformatter = new SimpleDateFormat("hh:mm");

String TimeChecker = formatter.format(ThisTime);

String DatabaseTime;

SQLiteDatabase db =getReadableDatabase();

Cursor c = db.query("SELECT " + KEY_DATE + "WHERE"+ KEY_TIME + "=" + DateChecker + "FROM" + DATABASE_TABLE);

if(c != null) {

return true;

}

else{

return false;

}

}

}

The method in which I am getting the error

public boolean DateAndTimeChecker() {

Date ThisDate = Calendar.getInstance().getTime();

SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

String DateChecker = formatter.format(ThisDate);

Date ThisTime = Calendar.getInstance().getTime();

SimpleDateFormat timeformatter = new SimpleDateFormat("hh:mm");

String TimeChecker = formatter.format(ThisTime);

String DatabaseTime;

SQLiteDatabase db =getReadableDatabase();

Cursor c = db.query("SELECT " + KEY_DATE + "WHERE"+ KEY_TIME + "=" + DateChecker + "FROM" + DATABASE_TABLE);

if(c != null) {

return true;

}

else{

return false;

}

}

Thank you very much in advance for the help

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值