Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在尝试创建sqlite表_Java_Sqlite - Fatal编程技术网

Java 正在尝试创建sqlite表

Java 正在尝试创建sqlite表,java,sqlite,Java,Sqlite,我在java中有一个数据库类,我试图在sqlite中创建一个新表。应用程序编译时会创建表,但由于某些原因,当我添加新行以添加新表时,不会创建表。我的db类如下所示: public static final String DATABASE_NAME = "something_db"; private Lock writeLock; private boolean locked; private DataBase(Context context) {

我在java中有一个数据库类,我试图在sqlite中创建一个新表。应用程序编译时会创建表,但由于某些原因,当我添加新行以添加新表时,不会创建表。我的db类如下所示:

public static final String DATABASE_NAME = "something_db";

    private Lock writeLock;
    private boolean locked;

    private DataBase(Context context)
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

        writeLock = new ReentrantLock();
    }

    @Override
    public void onCreate(SQLiteDatabase db)
    {
        onCreateV1(db);
        onCreateV2(db);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
    {
        if(oldVersion == 1 && newVersion == 2)
        {
            onCreateV2(db);
        }
    }

    private void onCreateV1(SQLiteDatabase db)
    {
        db.execSQL("create table schedule (id integer, day integer, start text, end text, points double, unique(id) on conflict replace)");
        db.execSQL("create table zone(id integer, name text, imageUrl text, imageFileName text, points double, unique(id) on conflict replace)");
        db.execSQL("create table zoneLocation(zoneId integer, locationOrder integer, latitude double, longitude double, unique(zoneId, locationOrder) on conflict replace)");
        db.execSQL("create table userLocation(id integer primary key, timestamp integer, latitude double, longitude double, speed double)");
        db.execSQL("create table userPoint(id integer primary key, timestamp text, scheduleId integer, scheduleMultiplier double, speedRangeId integer, speedRangeMultiplier double, zoneId integer, zoneMultiplier double, latitude double, longitude double, total double, sent integer)");
        db.execSQL("create table userTransaction(userId integer, date text, points double, unique(userId, date) on conflict replace)");
        db.execSQL("create table speedRange(id integer, name text, lowerLimit double, points double, unique(id) on conflict replace)");
我尝试添加新行以创建新表,但每次编译应用程序时,它都会告诉我

E/SQLiteLog:(1)没有这样的表:UserTopChallengers


不应该只是沿着正在创建的其他表添加行就足够了吗?为什么我添加的表没有与其他表一起创建

创建数据库时,
onCreate
方法只运行一次。如果删除应用程序的数据或卸载应用程序,则作为应用程序数据一部分的数据库将被删除,然后将运行
onCreate
方法。请注意,删除应用程序的数据将丢失您可能拥有的所有数据

您的
onUpgrade
方法可能会工作,也可能不工作(无法使用提供的部分代码),可能是后者,因为您似乎没有删除表(例如
DROP TABLE Your_TABLE_name;
),因此,由于表已经存在,您将得到错误 -(
CREATE TABLE IF NOT EXISTS…。
可以避免此问题,但即使是任何修改(例如,新列)也不会添加)


您可能会发现删除应用程序的数据或卸载应用程序然后重新运行应用程序更简单。如果没有完整的代码,就无法给出具体的解决方案。

您能告诉我们您正在使用的代码行应该添加一个新行吗?您发布的代码似乎已经结束。您没有在上面的代码中创建UserTopChallenger更新您的有问题的代码以获得更好的帮助。