I have the following error when the application runs on Android 4.0 and lower. When I run in API 21 or 23 I didn't have any problem. What's wrong?
03-13 20:46:29.206 1459-1459/com.josepjlh.freshphone I/Database: sqlite returned: error code = 1, msg = near ",": syntax error
03-13 20:46:29.206 1459-1459/com.josepjlh.freshphone E/Database: Failure 1 (near ",": syntax error) on 0x99b52c8 when preparing 'insert into Móviles values(null,"a","a","a","a","a","a","b","c","d","e","f","g","a"),(null,"a","a","a","a","a","a","a","a","a","a","a","a","a"),(null,"a","a","a","a","a","a","a","a","a","a","a","a","a")'.
03-13 20:46:29.206 1459-1459/com.josepjlh.freshphone D/AndroidRuntime: Shutting down VM
03-13 20:46:29.211 1459-1459/com.josepjlh.freshphone W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xb60454f0)
03-13 20:46:29.211 1459-1459/com.josepjlh.freshphone E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.josepjlh.freshphone/com.josepjlh.freshphone.MainActivity4}: android.database.sqlite.SQLiteException: near ",": syntax error: insert into Móviles values(null,"a","a","a","a","a","a","b","c","d","e","f","g","a"),(null,"a","a","a","a","a","a","a","a","a","a","a","a","a"),(null,"a","a","a","a","a","a","a","a","a","a","a","a","a")
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: near ",": syntax error: insert into Móviles values(null,"a","a","a","a","a","a","b","c","d","e","f","g","a"),(null,"a","a","a","a","a","a","a","a","a","a","a","a","a"),(null,"a","a","a","a","a","a","a","a","a","a","a","a","a")
at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
at com.josepjlh.freshphone.QuotesReaderDbHelper.onUpgrade(QuotesReaderDbHelper.java:29)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:132)
at com.josepjlh.freshphone.QuotesDataSource.<init>(QuotesDataSource.java:109)
at com.josepjlh.freshphone.MainActivity4.onCreate(MainActivity4.java:30)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
My files:
QuotesDataSource.java
public class QuotesDataSource {
//Metainformación de la base de datos
public static final String QUOTES_TABLE_NAME = "Móviles";
public static final String STRING_TYPE = "text";
public static final String INT_TYPE = "integer";
//Campos de la tabla Quotes
public static class ColumnQuotes{
public static final String ID_QUOTES = BaseColumns._ID;
public static final String NOMBRE_QUOTES = "nombre";
public static final String PRECIO_QUOTES = "precio";
public static final String PANTALLA_QUOTES = "pantalla";
public static final String CAMARA_QUOTES = "camara";
public static final String RENDIMIENTO_QUOTES = "rendimiento";
public static final String YEAR_QUOTES = "year";
public static final String IMAGE_QUOTES = "image";
public static final String ENLACE_QUOTES = "enlace";
public static final String DESCRIPTION_QUOTES = "description";
public static final String PRECIO_QUOTES2 = "precio2";
public static final String PANTALLA_QUOTES2 = "pantalla2";
public static final String CAMARA_QUOTES2 = "camara2";
public static final String RENDIMIENTO_QUOTES2 = "rendimiento2";
}
//Script de Creación de la tabla Quotes
public static final String CREATE_QUOTES_SCRIPT =
"create table "+QUOTES_TABLE_NAME+"(" +
ColumnQuotes.ID_QUOTES+" "+INT_TYPE+" primary key autoincrement," +
ColumnQuotes.NOMBRE_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.PRECIO_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.PANTALLA_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.CAMARA_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.RENDIMIENTO_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.YEAR_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.IMAGE_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.ENLACE_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.DESCRIPTION_QUOTES+" "+STRING_TYPE+" not null," +
ColumnQuotes.PRECIO_QUOTES2+" "+STRING_TYPE+" not null," +
ColumnQuotes.PANTALLA_QUOTES2+" "+STRING_TYPE+" not null," +
ColumnQuotes.CAMARA_QUOTES2+" "+STRING_TYPE+" not null," +
ColumnQuotes.RENDIMIENTO_QUOTES2+" "+STRING_TYPE+" not null)";
//Scripts de inserción por defecto
public static final String INSERT_QUOTES_SCRIPT =
"insert into "+QUOTES_TABLE_NAME+" values(" +
"null," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"b\"," +
"\"c\"," +
"\"d\"," +
"\"e\"," +
"\"f\"," +
"\"g\"," +
"\"a\")," +
"(null," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\")," +
"(null," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\"," +
"\"a\")";
private QuotesReaderDbHelper openHelper;
private SQLiteDatabase database;
public QuotesDataSource(Context context) {
//Creando una instancia hacia la base de datos
openHelper = new QuotesReaderDbHelper(context);
database = openHelper.getWritableDatabase();
}
public Cursor getPhonesByFilters(String v1, String v2, String v3, String v4){
String columns[] = new String[]{ColumnQuotes.ID_QUOTES, ColumnQuotes.NOMBRE_QUOTES, ColumnQuotes.YEAR_QUOTES, ColumnQuotes.IMAGE_QUOTES, ColumnQuotes.ENLACE_QUOTES, ColumnQuotes.DESCRIPTION_QUOTES};
String selection = "(" + ColumnQuotes.PRECIO_QUOTES + "=? OR " + ColumnQuotes.PRECIO_QUOTES2 + "=?" + ") AND " +
"(" + ColumnQuotes.PANTALLA_QUOTES + "=? OR " + ColumnQuotes.PANTALLA_QUOTES2 + "=?" + ") AND " +
"(" + ColumnQuotes.CAMARA_QUOTES + "=? OR " + ColumnQuotes.CAMARA_QUOTES2 + "=?" + ") AND " +
"(" + ColumnQuotes.RENDIMIENTO_QUOTES + "=? OR " + ColumnQuotes.RENDIMIENTO_QUOTES2 + "=? )";
String selectionArgs[] = new String[]{v1, v1, v2, v2, v3, v3, v4, v4};
return database.query(
QUOTES_TABLE_NAME,
columns,
selection,
selectionArgs,
null,
null,
null
);
}
}
QuotesReaderDbHelper.java
public class QuotesReaderDbHelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Móviles.db";
public static final int DATABASE_VERSION = 62;
public QuotesReaderDbHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//Crear la tabla Quotes
db.execSQL(QuotesDataSource.CREATE_QUOTES_SCRIPT);
//Insertar registros iniciales
db.execSQL(QuotesDataSource.INSERT_QUOTES_SCRIPT);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.delete("Móviles", null, null);
db.execSQL(QuotesDataSource.INSERT_QUOTES_SCRIPT);
}
}
Aucun commentaire:
Enregistrer un commentaire