SQLite 两次调用相同的 INSERT 命令

SQLite calls the same INSERT command twice

我试图插入基于两个数组的多个数据。两者包含不同的价值。我想将它们插入同一个 table.

在我的 DBHandler 中,我写了如下的 INSERT 语句

public void addData(Foto foto) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_TGL, foto.getDate());
    values.put(KEY_SITEID, foto.getSiteid());
    values.put(KEY_KATEGORI, foto.getKategori());
    values.put(KEY_FILENAME, foto.getFilename());
    values.put(KEY_PATH, foto.getPath());

    db.insert(TABLE_SHOPS, null, values);
    db.close();
}

在我的 activity 中。我是这样写的

for(int i=0;i<=namefile.length;i++){
            Bitmap[] bitmap = new Bitmap[namefile.length];
            FileOutputStream outputStream = new FileOutputStream(String.valueOf(namefile[i]));
            bitmap[i] = BitmapFactory.decodeByteArray(decodedString[i],0,decodedString[i].length);
            bitmap[i].compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
            outputStream.close();

            MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), namefile[i].getAbsolutePath(), namefile[i].getName(), namefile[i].getName());

            db.addData(new Foto(fDate,siteid,"genset_progres",namefile[i].getName(),namefile[i].getAbsolutePath()));
        }

        for(int a=0;a<=var.length;a++){
            db.addData(new Foto(fDate,siteid,"genset_progres","",var[a]));
        }

我打算将 namefile 的数据和 var 的数据插入同一个 table。所以我像上面那样写...但是当我调用它们时,只有名称文件被插入到数据库中。抱歉,我不太了解循环和 SQLITE 在 android 上的工作方式,因为这是我第一次尝试。也许你们可以帮助我。我会很感激。

如果有任何我应该提供的...请随时询问。

替换

for(int i=0;i<=namefile.length;i++)

for(int i=0;i<namefile.length;i++)

还有

for(int a=0;a<=var.length;a++)

for(int a=0;a<var.length;a++)

这样您就可以 运行 没有 ArrayOutOfBoundsException 的代码。