我创建了一个警报服务并在main activity中调用它,但是得到这个错误:"unable to start service".............我在db.java中创建表,并在alarmservice中通过InsertMagnt设置变量。
DB DataBase = new DB();
DataBase.InsertMagnt(Acce_x, Acce_y, Acce_z, "", "", 1);
DataBase.InsertMagnt(Meg_x, Meg_y, Meg_z, datetime, "", 2);
DataBase.InsertMagnt(Tilt_x, Tilt_y, Tilt_z, datetime, Direct, 3);
DataBase.InsertMagnt(lon, lat, 0, datetime, "", 4);主要活动是:
Intent AlarmIntent = new Intent(MainActivity.this, AlarmService.class);
pending = PendingIntent.getService(MainActivity.this, 0, AlarmIntent, 0);
alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
btnStart.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 5);
alarm.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 10 * 1000, pending);
Toast.makeText(MainActivity.this, "Service Start", Toast.LENGTH_SHORT).show();
}
});我得到了这个错误:
08-08 13:24:21.334: E/AndroidRuntime(9000): java.lang.RuntimeException: Unable to start service com.example.farzaneh.AlarmService@417c9cd8 with Intent { flg=0x4 cmp=com.example.farzaneh/.AlarmService (has extras) }: android.database.sqlite.SQLiteException: unrecognized token: "')" (code 1): , while compiling: INSERT INTO Acce_Log (X,Y,Z,Date) VALUES (0.0,0.0,0.0')发布于 2014-08-08 17:02:55
这条insert语句是怎么回事
INSERT INTO Acce_Log (X,Y,Z,Date) VALUES (0.0,0.0,0.0')//date is not inserted and the '您已经指定了four values will be inserted but inserting only three,和'.Remove它,并将日期作为最后一个参数传递
发布于 2014-08-08 17:47:31
萨拉姆!
您的错误是因为您在向SQLite表中插入一行时犯了错误(请再次查看您给定的错误!)
INSERT INTO Acce_Log (X, Y, Z, Date) VALUES (0.0, 0.0, 0.0 ')
unrecognized token ----^请更正insert语句。还要注意,SQLite不提供任何用于存储日期的数据类型,您应该以字符串或长格式存储日期。
我建议你使用long!使用Calendar对象将日期转换为自纪元(在UTC时区中)以来的毫秒数,现在可以将其存储在SQLite中
更新#1
假设我在SQLite数据库中有以下表
column name type
-------------------------
GID INTEGER
Name TEXT
Quan INTEGER
Surname TEXT现在,我想用一些示例数据填充这个表,为此,我将使用以下函数。
public void addRow() {
ContentValues contentValues = new ContentValues();
contentValues.put("GID", 123);
contentValues.put("Name", "Edward");
contentValues.put("Quan", 12);
contentValues.put("Surname", "Kenway");
mDataBase.insert("Your table name", null, contentValues);
}https://stackoverflow.com/questions/25199547
复制相似问题