gpt4 book ai didi

android - Android SQL错误,将无法创建表

转载 作者:行者123 更新时间:2023-12-03 08:16:22 24 4
gpt4 key购买 nike

我是编程机器人的新手,我正在尝试制作一个SQLite DAtabase,但我一直收到此错误

06-05 17:10:59.164: ERROR/AndroidRuntime(268): FATAL EXCEPTION: main

06-05 17:10:59.164: ERROR/AndroidRuntime(268): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.c.notes/com.c.notes.Notes}: android.database.sqlite.SQLiteException: no such column: _id: , while compiling: SELECT _id, title, body FROM note

我读到其他人和我有同样的问题,但是所有解决方案都没有用。
这是我认为问题所在的数据库适配器类
package com.c.notes;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class NotesDataBase {

/* public static final String Note_TITLE = "noteTitle";
public static final String Note = "notee"; //these dont work must need other form for sql to work
public static final String NoteID = "Noteid";
*/
public static final String KEY_TITLE = "title";
public static final String KEY_BODY = "body";
public static final String KEY_ROWID = "_id";

private static final String Iden = "notesLinkCable";
private ACTNotesDBBuddy DatBuddy;//dbhelper was a coni
private SQLiteDatabase ACTNotesDB;
/** private static final String Create_DataBase =
"create table note (Noteid integer primary key autoincrement, "
+ "noteTitle text not null, notee text not null);";
*/
private static final String DATABASE_CREATE =
"create table notes (_id integer primary key autoincrement, "
+ "title text not null, body text not null);";

private static final String DBname = "DatBass";
private static final String DatBassTable = "note";
private static final int DatBassVER = 2;

private final Context coni;



private static class ACTNotesDBBuddy extends SQLiteOpenHelper {

ACTNotesDBBuddy(Context context){
super(context, DBname, null, DatBassVER);
}

@Override//1
public void onCreate(SQLiteDatabase sld){
sld.execSQL(DATABASE_CREATE);//so the data has so bs stuff pushed in it already lol
}

@Override//2
public void onUpgrade(SQLiteDatabase slld, int old, int newV){
Log.w(Iden, "I guess I'm upgrading sdl from ver" + old + " to " + newV +
" ps I hear this will kill off the old king and knights saved");//this is a logCat tag I believe anyway this kills old data for an update...wont be doing that

slld.execSQL("DROP TABLE IF EXISTS " + KEY_TITLE);
onCreate(slld);
}

}
//3
public NotesDataBase(Context con){
this.coni=con;
}
//4
public NotesDataBase open() throws SQLException{
DatBuddy = new ACTNotesDBBuddy(coni);
ACTNotesDB =DatBuddy.getWritableDatabase();
return this;
}
//5
public void close(){
DatBuddy.close();
}
//6 a 10
public long createNote( String name, String body){
ContentValues Orgin = new ContentValues();
Orgin.put(KEY_TITLE, name);
Orgin.put(KEY_BODY,body);//my intial thought is this will over right each other but i believe its kinda like a stackish thing :)

return ACTNotesDB.insert(DatBassTable ,null,Orgin);
}

//7a6
public boolean deleteNote(long locoRow){
return ACTNotesDB.delete(DatBassTable,KEY_ROWID + "=" + locoRow,null)>0;
}
//8
public Cursor fetchAllNotes(){
return ACTNotesDB.query(DatBassTable, new String []{ KEY_ROWID,KEY_TITLE,KEY_BODY}, null, null, null, null, null);
}



//9a7
public Cursor fetchNote(long rid) throws SQLException{
Cursor cursor = ACTNotesDB.query(true, DatBassTable, new String [] {KEY_ROWID,KEY_TITLE,KEY_BODY}, KEY_ROWID +"="+rid, null, null, null, null, null);

if(cursor != null){
cursor.moveToFirst();
}
return cursor;
}
//10
public boolean updateNote(long loco, String name, String note) {
ContentValues info = new ContentValues();
info.put(KEY_TITLE, name);
info.put(KEY_BODY, note);
return ACTNotesDB.update(DatBassTable, info, KEY_ROWID + "=" + loco, null) > 0;
}




}

最佳答案

您要查询的表在数据库表名称变量中另存为“注释”。您将表创建为带有“s”的“notes”。

关于android - Android SQL错误,将无法创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6244537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com