我有一个SQliteDatabase,其列名为" MINIATURA"在listview中设置微缩路径的位置。如果打开数据库我可以看到里面有路径的列,但是如果我在Cursor适配器中调用它会给我错误
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)
这是我的光标适配器
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);
}
}
如果我在另一列中更改database_ob.MIN,则可以正常工作。 我做错了什么?
编辑:这是我创建数据库的方式
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);
}
}
答案 0 :(得分:0)
抓住数据库并在sqlite管理器中将其可视化。
我可以看到你的版本仍然是1.也许你在没有MINIATURA列的情况下进行编辑,当前设备上的数据库没有。
也许如果您将版本更改为2,那么将DB升级到最新版本可以解决问题吗?
答案 1 :(得分:0)
删除数据库并再次创建。确定您正在查看没有该列的旧副本。
答案 2 :(得分:0)
我确定您更改了列的名称 “ MINIATURE ”改为“ MINIATURA ”:)
所以数据库已经创建了列“ MINIATURE ”,因此找不到你的名字“ MINIATURA ”,
解决方案很简单,只需卸载app并安装新的或增加db版本。
希望这会对你有所帮助。