Android:Sugar ORM没有这样的表格例外

问题描述 投票:36回答:21

当我使用No Such tableSugar ORM时,我得到了GPU image Android Library例外。我正在使用Gradle和Android Studio。一旦我删除GPU图像这个问题就解决了。所以我不知道什么导致这个例外。关于这个例外的细节也在这个git issue中讨论,似乎很多人仍然面对它。

我的崩溃日志发布在下面

> 10-09 11:30:21.511 4326-4831/com.example.app E/SQLiteLog: (10) Failed
> to do file read, got: 0, amt: 100, last Errno: 2 10-09 11:30:26.506
> 4326-4831/com.example.app E/SQLiteLog: (1) no such table: IMAGE 10-09
> 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime: FATAL
> EXCEPTION: AsyncTask #1 10-09 11:30:26.516 4326-4831/com.example.app
> E/AndroidRuntime: java.lang.RuntimeException: An error occured while
> executing doInBackground() 10-09 11:30:26.516
> 4326-4831/com.example.app E/AndroidRuntime:     at
> android.os.AsyncTask$3.done(AsyncTask.java:299) 10-09 11:30:26.516
> 4326-4831/com.example.app E/AndroidRuntime:     at
> java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> java.util.concurrent.FutureTask.setException(FutureTask.java:219)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> java.util.concurrent.FutureTask.run(FutureTask.java:239) 10-09
> 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 10-09
> 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> java.lang.Thread.run(Thread.java:838) 10-09 11:30:26.516
> 4326-4831/com.example.app E/AndroidRuntime:  Caused by:
> android.database.sqlite.SQLiteException: no such table: IMAGE (code
> 1): , while compiling: SELECT * FROM IMAGE 10-09 11:30:26.516
> 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
> Method) 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:
> at
> android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:886)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:497)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37) 10-09
> 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
> 10-09 11:30:26.516 4326-4831/com.example.app E/AndroidRuntime:     at
> android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1238)
android sqlite gpuimage sugarorm
21个回答
96
投票

我有同样的问题,它与Instant Run有关。禁用即时运行,重新安装应用程序,它的工作原理。

有关如何启用或禁用Instant Run的详细信息,请参阅this link


5
投票

在我的例子中,我从AndroidManifest.xml中删除了以下行,它可以工作!

enter image description here


4
投票

我也有这个问题,我的班级只有1个String属性。我使用的是1.3版。只需从AndroidManifest.xml文件中注释此代码,您就可以开始了:)

<meta-data
 android:name="DOMAIN_PACKAGE_NAME"
 android:value="com.project.database.entities" />

参考:

https://github.com/satyan/sugar/issues/75


4
投票

我有这个问题。我执行了这里发布的所有建议。但都没有奏效。然后我把所有的一起应用,最后摆脱了那个问题。我做了什么-

1. Disabled instant run. (as Parth Vora said.)
2. Then I added the following class-

   import android.app.Application;
   import android.content.res.Configuration;
   import com.orm.SugarApp;
   import com.orm.SugarContext;

   public class SugarOrmTestApplication extends SugarApp {

      @Override
      public void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
      }

      @Override
     public void onCreate() {
        super.onCreate();
        SugarContext.init(getApplicationContext());
        Book.findById(Book.class, (long) 1);
     }

     @Override
     public void onLowMemory() {
       super.onLowMemory();
     }

     @Override
     public void onTerminate() {
       super.onTerminate();
     }
 }

 3. Modified manifest file-
    <application
      //Added the following lines-
       android:name="SugarOrmTestApplication">
       <meta-data android:name="DATABASE" android:value="sugar_example_new.db" />
       <meta-data android:name="VERSION" android:value="2" />
       <meta-data android:name="QUERY_LOG" android:value="true" />
    </application>

这是我的模特课 -

public class Book extends SugarRecord {
   String title;
   String edition;

   public Book(){
   }

   public Book(String title, String edition){
      this.title = title;
      this.edition = edition;
   }
}

现在我的应用程序运行良好


2
投票

你有没有尝试将版本更改为2 ???这可能是不同的版本,也尝试其他值。

另外,确保SugarRecord类上有空构造函数。

如果您正在使用,则更改数据库名称是另一个approuche。

如果您在不卸载应用程序的情况下创建表格,请将版本号设为+1。


2
投票

正如其他人所说,Android Studio即时运行可能是问题(known SugarORM issue),试着把它关掉。

但是,我遇到了同样的问题,这对我来说还不够,问题依然存在。我通过将清单中的allowBackup="true"更改为false,运行应用程序并删除>之后重新安装应用程序来修复此问题。

为什么我猜这就是问题:我发现即使重新安装后我的偏好也会保存。如果这也发生在损坏的SQL表中(由于即时运行),那么即使重新安装也无法修复它。将allowBackup更改为false并重新安装后,我的问题立即得到解决。我还无法重现错误,因此也无法重现修复。

希望这个添加可能会帮助像我这样的头痛的人!


1
投票

当您开始初始开发并且不希望为模型的快速迭代期间所做的更改而增加数据库版本时(我在充实无法预料的要求时会做很多事情),请在应用程序启动期间使用它-up:

SugarDb sugarDb = new SugarDb(getApplicationContext());
new File(sugarDb.getDB().getPath()).delete();
Model.findById(Model.class, (long) 1); // Perform this for each SugarRecord  model

// Insert test data:
Modelrecord = new Model("Model Title", "Model content", false);
record.save();

警告 - 这将删除数据库中的所有数据,因此调试会话之间的持久更改将不起作用,但它允许您发布数据库的应用程序版本1的版本1。

我不建议在版本1正式发布后执行此操作,请确保使用SugarORM Migration Method记录所需的所有更改。


1
投票

确保元数据包名称指向您放置模型实体而非应用程序包名称的位置


1
投票

我有同样的问题并解决了它不是通过禁用即时运行,而是通过更改我的:

<meta-data android:name="VERSION" android:value="1" />

<meta-data android:name="VERSION" android:value="2" />

由于最低值应为2


1
投票

问题是,在我的应用程序中,我有两个不同的数据库。所以,我只将版本1改为版本2.我的第一个DB版本为1


0
投票

如github repo的README中所述,如果您使用的是proguard,则应确保实体保持未混淆,以便正确地命名表和列。

为此,请将此行添加到proguard-rules.pro

-keep class com.yourpackage.yourapp.domainclasspackage.** { *; }

67
投票

如果您使用的是Android Studio 2.0

有同样的问题!

因此,即时运行与Sugar ORM不兼容

  • 开放式设置
  • enter image description here
  • 现在运行你的项目

请享用!


0
投票

在我的情况下,它是库糖的问题。它有获取域类的错误方法(com.orm.util.ReflectionUtil#getDomainClasses)。该方法始终不返回任何类。所以Sugar可能不会初始化数据库表。我已降级为gradle 1.3.0(该方法正常工作)并且问题消失了。


0
投票

请检查这家酒店

    <`meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="trending.hashtags.pojo" />`

这应该是您的POJO类不仅仅是包名称的地方。


30
投票

我面临同样的问题。禁用“即时运行”并没有解决问题。我也没有启用proguard。后来我从android清单中删除了所有的sugarORM元数据(查询日志除外),解决了这个问题。所以从android清单中删除以下3行:

    <meta-data android:name="DATABASE" android:value="edikodik.db" />
    <meta-data android:name="VERSION" android:value="2" />
    <meta-data android:name="QUERY_LOG" android:value="true" /> 

编辑:根据jrhamza的评论,如果上述解决方案不起作用,请尝试禁用即时运行。


15
投票

我正在使用1.5版本,并尝试了很多方法,但没有工作。

我找到了解决方案!

这将强制在启动应用程序时创建表:

public class SugarOrmTestApplication extends SugarApp {
    @Override
    public void onCreate() {
        super.onCreate();
        SugarContext.init(getApplicationContext());

        // create table if not exists
        SchemaGenerator schemaGenerator = new SchemaGenerator(this);
        schemaGenerator.createDatabase(new SugarDb(this).getDB());
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        SugarContext.terminate();
    }
}

13
投票

如果在代码中添加新模型(新表),则需要在Manifest文件中更改数据库版本。新值>旧值(更新)

 <meta-data
            android:name="VERSION"
            android:value="1"/>

10
投票

我也遇到过这个问题。在猎杀了2天后,我通过以下技巧解决了它在android studio中

步骤1.在app的build.gradle文件中编写'com.github.satyan:sugar:1.5'编译器

步骤2.在项目的build.gradle文件的依赖项中编写类路径'com.android.tools.build:gradle:2.1.0'

步骤3.数据库版本应大于1,始终如sugarORM中所述


8
投票

禁用您的即时运行转到文件>设置>构建,执行,部署>即时运行


6
投票

要创建模型表,我会在应用程序启动后对所有模型执行此操作:

Book.findById(Book.class, (long) 1);
Car.findById(Car.class, (long) 1);

我的应用程序扩展了SugarApp,因此这会强制Sugar创建所有表。

另一方面,要更新数据库,必须将版本更改为2。

最后,拥有一个空构造函数是必须的。

希望这可以帮助! ;)


6
投票

解决

我不知道但SugarDb.onCreate没有被调用。因此,将此代码放在MainActivity.onCreate中,Sugar ORM将起作用

    SugarDb db = new SugarDb(this);
    db.onCreate(db.getDB());
© www.soinside.com 2019 - 2024. All rights reserved.