如何捕获没有这样的 table 错误糖?

How to catch no such table error sugar?

我收到这个错误
Caused by: android.database.sqlite.SQLiteException: no such table:
有什么方法可以捕捉到它。
我尝试了 try and catch,但无法正常工作,应用程序崩溃了
我的代码

JsonStroageMilla jsonStroageMilla=new JsonStroageMilla();
jsonStroageMilla.findById(JsonStroageMilla.class,1);

我的class

    @Keep
    public class JsonStroageMilla extends SugarRecord {
        public JsonStroageMilla(){

        }
    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    String data,time;
  }


完整的错误代码

FATAL EXCEPTION: main Process: com.valyangadi, PID: 16477 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app/ChecckoutActivity062802}: android.view.InflateException: Binary XML file line #23: Binary XML file line #32: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #32: Error inflating class fragment at android.view.LayoutInflater.inflate(LayoutInflater.java:539) at android.view.LayoutInflater.inflate(LayoutInflater.java:423) at android.view.LayoutInflater.inflate(LayoutInflater.java:374) at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at com.shopify.sample.checkout.ChecckoutActivity062802.onCreate(ChecckoutActivity062802.java:18) at android.app.Activity.performCreate(Activity.java:6245) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5443)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)  Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.rInflate(LayoutInflater.java:838) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:971) at android.view.LayoutInflater.rInflate(LayoutInflater.java:831) at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) at android.view.LayoutInflater.inflate(LayoutInflater.java:515) at android.view.LayoutInflater.inflate(LayoutInflater.java:423)  at android.view.LayoutInflater.inflate(LayoutInflater.java:374)  at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)  at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  at com.shopify.sample.checkout.ChecckoutActivity062802.onCreate(ChecckoutActivity062802.java:18)  at android.app.Activity.performCreate(Activity.java:6245)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)  at android.app.ActivityThread.-wrap11(ActivityThread.java)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5443)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)  Caused by: android.database.sqlite.SQLiteException: no such table: JSON_STROAGE_MILLA (code 1): , while compiling: SELECT * FROM JSON_STROAGE_MILLA at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:58) at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:37) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316) at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163) at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034) at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1240) at com.orm.SugarRecord.find(SugarRecord.java:201) at com.orm.SugarRecord.listAll(SugarRecord.java:127) at

添加一个空构造函数并确保将数据库值更新为 1,因此

public JsonStroageMilla() {}

<meta-data
android:name="VERSION"
android:value="2"/>
  • 尝试禁用即时
  • 首先从 device/emulator.
  • 中卸载您的应用
  • 然后清理项目(Android工作室、构建、清理项目)。
  • 现在 运行 您的应用程序。