android – OrmLite SQLiteException:没有这样的表

android – OrmLite SQLiteException:没有这样的表,第1张

概述我在 Android上使用以下DatabaseHelper和 OrmLite: public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static final String TAG = "databaseHelper"; private static final String DATABASE 我在 Android上使用以下DatabaseHelper和 OrmLite:

public class DatabaseHelper extends OrmlitesqliteOpenHelper {    private static final String TAG = "databaseHelper";    private static final String DATABASE_name = "mydb.db";    // Mind onUpgrade when changing this!    private static final int DATABASE_VERSION = 18;    private Dao<Account,Integer> accountDao;    public DatabaseHelper(Context context) {        super(context,DATABASE_name,null,DATABASE_VERSION);    }    @OverrIDe    public voID onCreate(sqliteDatabase sqliteDatabase,ConnectionSource connectionSource) {        try {            tableUtils.createtable(connectionSource,Account.class);        } catch (sqlException e) {            ExceptionHandler.handleException(e);        }    }    @OverrIDe    public voID onUpgrade(sqliteDatabase database,ConnectionSource connectionSource,int oldVersion,int newVersion) {    }    private Dao<Account,Integer> getAccountDao() {        if (accountDao == null) {            try {                accountDao = getDao(Account.class);            } catch (Exception exc) {                Log.e(TAG,exc.toString());                ExceptionHandler.handleException(exc);            }        }        return accountDao;    }    public voID writeAccount(Account account) {        try {            tableUtils.createtableIfNotExists(connectionSource,IWAccount.class);            getAccountDao().createOrUpdate(account);        } catch (sqlException exc) {            Log.e(TAG,exc.toString());            ExceptionHandler.handleException(exc);        }    }    public voID deleteIWAccount() {        try {            tableUtils.cleartable(connectionSource,Account.class);        } catch (sqlException e) {            Log.e(TAG,e.toString());            ExceptionHandler.handleException(e);            e.printstacktrace();        }    }    public Account getAccount() {        List<Account> accounts = null;        try {            accounts = getAccountDao().queryForAll();        } catch (sqlException e) {            e.printstacktrace();            ExceptionHandler.handleException(e);        }        if (accounts == null || accounts.isEmpty()) {            return null;        }        if (accounts.size() > 1) {            ExceptionHandler.handleException(new IllegalStateException("More than 1 IWAccounts in DB"));        }        return accounts.get(0);    }}

处理的例外都写入Crittercism.

对于小但不可忽略的用户数,会发生以下异常:

java.sql.sqlException: Problems executing AndroID query: SELECT * FROM `account`at com.j256.ormlite.misc.sqlExceptionUtil.create(sqlExceptionUtil.java:22)[...]Caused by: androID.database.sqlite.sqliteException: no such table: account (code 1):,while compiling: SELECT * FROM `account`

我的DatabaseHelper尝试在其onCreate()方法中为Account创建表.

我的第一个想法是在onCreate()中创建表时出错了.批评虽然让我浏览发生此错误的用户的所有其他已处理或未处理的异常,并且在创建表时没有任何异常.

关于这可能是什么问题的任何想法?

编辑:这是我的DatabaseHelper的简化版本,与其他Daos和表相同的错误.使用的类非常简单,这里是Account类:

public class Account implements Serializable {    //    ID is set so we always update the old object instead of creating a new one in the db helper    @DatabaseFIEld(ID = true,canBeNull = false)    private int mID = 0;    @DatabaseFIEld    private String ID;    @DatabaseFIEld    private String username;    @DatabaseFIEld    private String displayname;}

EDIT2:我对应用程序进行了更新,我的持久化类使用@Databasetable注释并重新创建(或尝试)onUpgrade()中的表,但问题仍然存在.

解决方法 从我所看到的,您在Account类中缺少@Databasetable注释.

从docs:

Annotation that marks a class to be stored in the database. […] You specify this annotation above the classes that you want to persist to the database.

以下应创建一个表帐户:

@Databasetablepublic class Account implements Serializable {    //    ID is set so we always update the old object instead of creating a new one in the db helper    @DatabaseFIEld(ID = true,canBeNull = false)    private int mID = 0;    @DatabaseFIEld    private String ID;    @DatabaseFIEld    private String username;    @DatabaseFIEld    private String displayname;}

您可以使用注释中的tablename字段来更改表名称,例如@Databasetable(tablename =“accounts”)否则文档状态:

If not set then the name is taken from the class name lowercased.

总结

以上是内存溢出为你收集整理的android – OrmLite SQLiteException:没有这样的表全部内容,希望文章能够帮你解决android – OrmLite SQLiteException:没有这样的表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1123540.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存