Java 数据可以';不能在Android中插入SqLite数据库
这是我保存数据的类Java 数据可以';不能在Android中插入SqLite数据库,java,android,database,sqlite,Java,Android,Database,Sqlite,这是我保存数据的类 public class Report { public String report_title=""; public String report_descrption=""; public String report_category=""; public String report_location_name=""; public String report_lat; public String report_long;
public class Report {
public String report_title="";
public String report_descrption="";
public String report_category="";
public String report_location_name="";
public String report_lat;
public String report_long;
public String report_media="";
}
这是我在数据库中插入一行的数据库处理程序类
public class DatabaseHandler extends SQLiteOpenHelper{
private static final String LOG = DatabaseHandler.class.getName();
// Database version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "reportsManager";
// Table names
private static final String TABLE_REPORT= "report";
// Helper Table Columns names
private static final String REPORT_TITLE="title";
private static final String REPORT_DESCRIPTION="description";
private static final String REPORT_CATEGORY="category";
private static final String REPORT_LOCATION_NAME="location";
private static final String REPORT_LAT="latitude";
private static final String REPORT_LONG="logitude";
private static final String REPORT_MEDIA="media";
// Helper table create statement
private static final String CREATE_TABLE_REPORT = "CREATE TABLE "
+ TABLE_REPORT + " ( " + REPORT_TITLE + " TEXT, " +
REPORT_DESCRIPTION+ " TEXT, " + REPORT_CATEGORY + " TEXT," + REPORT_LOCATION_NAME +
" TEXT, "+ REPORT_LAT+" TEXT, "+ REPORT_LONG+" TEXT, "+REPORT_MEDIA+" TEXT"+")";
// Constructor
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//Creating required tables
db.execSQL(CREATE_TABLE_REPORT);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + CREATE_TABLE_REPORT);
// create new tables
onCreate(db);
}
void addReport(Report reports) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(REPORT_TITLE, reports.report_title);
values.put(REPORT_DESCRIPTION, reports.report_descrption);
values.put(REPORT_CATEGORY, reports.report_category);
values.put(REPORT_LOCATION_NAME, reports.report_location_name);
values.put(REPORT_LAT, reports.report_lat);
values.put(REPORT_LONG, reports.report_long);
values.put(REPORT_MEDIA, reports.report_media);
// Inserting Row
db.insert(TABLE_REPORT, null, values);
db.close(); // Closing database connection
}
}
现在,如果我将以下错误插入数据库,则会在LogCat中发生。有人能帮我吗
android.database.sqlite.SQLiteException: table report has no column named logitude: , while compiling: INSERT INTO report(category,title,logitude,latitude,media,location,description) VALUES (?,?,?,?,?,?,?)
看起来您的表使用了
long
,您正在尝试插入到logitude
中,它应该是经度。我已将“logitude”更改为“longitude”,但出现了相同的错误!您的报表
类没有逻辑度或经度,它有很长的时间。试着用它来代替。我认为这不重要。然而,我已经根据你的建议改变了,同样的事情发生了(