SQLiteDatabase列不存在



我有一个SQliteDatabase,它有一个名为"MINIATURA"的列,其中有要在列表视图中设置的微型的路径。如果打开数据库,我可以看到里面有路径的列,但如果我在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);
 }
}

这是数据库https://i.stack.imgur.com/h9Z1A.jpg

获取数据库并在sqlite管理器中对其进行可视化。

我可以看到你的版本仍然是1。也许你在编辑它时没有MINIATURA列,而设备上当前的DB没有它。

也许如果你把版本改为2,那么它会把数据库升级到最新版本,可以解决这个问题吗?

删除数据库并重新创建。我确信您正在查看的是一个没有列的旧副本。

我确信您更改了列的名称"微型"到"MINIATURA":)

所以数据库已经创建了列"MINIATURE",所以找不到您的名称"MINIATURA

解决方案很简单,只需卸载应用程序并安装新的应用程序或增加数据库版本即可。

希望这对你有帮助。

相关内容

  • 没有找到相关文章

最新更新