Android 不要启动服务
我创建了一个报警服务,并在主活动中调用它,但出现以下错误:无法启动服务。。。。。。。。。。。。。 我在db.java中创建表,并在alarmservice中通过InsertMagnt设置变量Android 不要启动服务,android,eclipse,sqlite,Android,Eclipse,Sqlite,我创建了一个报警服务,并在主活动中调用它,但出现以下错误:无法启动服务。。。。。。。。。。。。。 我在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); DataB
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')
这个insert语句是怎么回事
INSERT INTO Acce_Log (X,Y,Z,Date) VALUES (0.0,0.0,0.0')//date is not inserted and the '
您已指定将插入四个值,但只插入三个值,请将其删除,并将日期作为最后一个参数传递给Salam
您的错误是因为在SQLite表中插入一行时出错。请再次查看给定的错误
INSERT INTO Acce_Log (X, Y, Z, Date) VALUES (0.0, 0.0, 0.0 ')
unrecognized token ----^
请更正您的插入声明。还要注意,SQLite不提供任何用于存储日期的数据类型,您应该以字符串或长格式存储日期
我建议你用久一点!使用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);
}
salam,我通过文本在acce_日志中创建了日期:“database.execSQLCREATE TABLE IF NOT EXISTS acce_log+ID INTEGER主键AUTOINCREMENT NOT NULL,+X DOUBLE,Y DOUBLE,Z DOUBLE,date text;”并通过database.execSQLINSERT将变量插入Acce_Log X,Y,Z,日期值++X+,+Y+,+Z+,“+Date+”@Farzanehabolqasimi请告诉我日期对象的类型是什么?@Farzanehabolqasimi为什么不使用ContentValues?它非常简单,而且将字符串连接在一起要好得多。如果您同意,请告诉我在回答中添加一些示例代码,我是否应该编写contentvalues而不是文本?我不知道这件事@Farzanehabolqasimi别担心,保持冷静!!!请查看或将日期保存为文本,是否知道sql中的数据类型日期?\@DividebyZero SQLite不提供任何用于存储日期的数据类型