vendredi 20 février 2015

SQLiteDatabase Column does not exist

I have a SQliteDatabase with a column named "MINIATURE" where there is the path of a miniature to set in the listview. If open the database I can see the column with the paths inside, but if I call it in the Cursor adapter it give me error



02-20 13:06:17.099: E/AndroidRuntime(17357): FATAL EXCEPTION: main
02-20 13:06:17.099: E/AndroidRuntime(17357): Process: info.androidhive.tabsswipe, PID: 17357
02-20 13:06:17.099: E/AndroidRuntime(17357): java.lang.IllegalArgumentException: column 'MINIATURA' does not exist
02-20 13:06:17.099: E/AndroidRuntime(17357): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:303)
02-20 13:06:17.099: E/AndroidRuntime(17357): at android.widget.SimpleCursorAdapter.findColumns(SimpleCursorAdapter.java:333)
02-20 13:06:17.099: E/AndroidRuntime(17357): at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:81)
02-20 13:06:17.099: E/AndroidRuntime(17357): at info.androidhive.tabsswipe.WeedCursorAdapter.<init>(WeedCursorAdapter.java:26)


and this is my cursor adapter



public class WeedCursorAdapter extends SimpleCursorAdapter
{
private Context context;
static RegistrationOpenHelperW database_ob;
RegistrationAdapterW adapter_db;




static String[] from = { database_ob.NAME , database_ob.MIN};
static int[] to = { R.id.tv_fnamew, R.id.img_row_w};

public WeedCursorAdapter(Context context, Cursor c)
{
super(context, R.layout.row_w, c, from, to );
this.context = context;
}

@Override
public void bindView(View view, Context context, Cursor cursor)
{
super.bindView(view, context, cursor);
ImageView img1 = (ImageView) view.findViewById(R.id.img_row_w);
Picasso.with(context)
.load("file://" + cursor.getString(6))
.fit()
.centerCrop()
//.resizeDimen(R.dimen.miniature_size, R.dimen.miniature_size)
.into(img1);
}
}


If I change database_ob.MIN in another column it works. What I made wrong?


EDIT: This is how I create the database



public class RegistrationOpenHelperW extends SQLiteOpenHelper{
public static final String DATABASE_NAME = "WEED_DB";
public static final String TABLE_NAME = "WEED_TABLE";
public static final int VERSION = 1;
public static final String KEY_ID = "_id";
public static final String NAME = "NOME";
public final static String CFS = "COFFEESHOP";
public static final String DESC = "DESCRIZIONE";
public static final String IMG1 = "IMG1";
public static final String IMG2 = "IMG2";
public static final String MIN = "MINIATURA";
public static final String SCRIPT = "create table " + TABLE_NAME + " ("
+ KEY_ID + " integer primary key autoincrement, " + NAME
+ " text not null, " + CFS + " text not null, " + DESC + " text not null,"
+ IMG1 + " text not null," + MIN + " text not null," + IMG2 + " text not null );";
public RegistrationOpenHelperW(Context context, String name,
CursorFactory factory, int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(SCRIPT);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("drop table " + TABLE_NAME);
onCreate(db);
}
}

Aucun commentaire:

Enregistrer un commentaire