gpt4 book ai didi

android - 没有这样的表 Sugar ORM

转载 作者:行者123 更新时间:2023-11-29 17:19:49 26 4
gpt4 key购买 nike

我的 Android 项目中有很多关于 Sugar ORM 的问题。

那是错误:

    05-07 18:50:42.173 7252-7252/net.elinformaticoenganchado.sergio.crossfighters E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.elinformaticoenganchado.sergio.crossfighters, PID: 7252
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.elinformaticoenganchado.sergio.crossfighters/net.elinformaticoenganchado.sergio.crossfighters.addPlan}: android.database.sqlite.SQLiteException: no such table: PLAN (code 1): , while compiling: INSERT OR REPLACE INTO PLAN(ID,NAME) VALUES (?,?)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.database.sqlite.SQLiteException: no such table: PLAN (code 1): , while compiling: INSERT OR REPLACE INTO PLAN(ID,NAME) VALUES (?,?)
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.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
at com.orm.SugarRecord.save(SugarRecord.java:280)
at com.orm.SugarRecord.save(SugarRecord.java:416)
at net.elinformaticoenganchado.sergio.crossfighters.addPlan.onCreate(addPlan.java:17)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
at android.app.ActivityThread.-wrap11(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

我的实体类是:

    package net.elinformaticoenganchado.sergio.crossfighters;

import com.orm.SugarRecord;
import com.orm.dsl.Unique;

/**
* Created by sergio on 7/05/16.
*/

public class Plan extends SugarRecord {
@Unique
String name;


// Default constructor is necessary for SugarRecord
public Plan() {

}

public Plan(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}

当我尝试执行下一个代码时出现问题:

package net.elinformaticoenganchado.sergio.crossfighters;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import java.util.List;

public class addPlan extends AppCompatActivity implements View.OnClickListener{

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_plan);

Plan plan = new Plan("Plan1");
plan.save();

List<Plan> plans = Plan.listAll(Plan.class);

for (int i = 0; i < plans.size(); i++) {
System.out.println("Plan: " + plans.get(i).getName());
}

}

@Override
public void onClick(View v) {

}
}

拜托,我需要帮助,我禁用了 Instant run 选项,就像在每个帖子中所说的那样,但它不起作用。

Settings

感谢您的帮助。

我的安卓 list :

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.elinformaticoenganchado.sergio.crossfighters"
android:versionCode="1"
android:versionName="1.0">

<application
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="com.orm.SugarApp">
<meta-data android:name="DATABASE" android:value="example.db" />
<meta-data android:name="VERSION" android:value="1" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="net.elinformaticoenganchado.sergio.crossfighters" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".chronometer" />
<activity android:name=".addPlan" />
</application>

</manifest>

最佳答案

这个问题可以通过创建一个空的“新版本迁移脚本文件”来解决。这可以通过以下简单地完成:

  1. 创建新的 Sugar 记录类。
  2. 在 Android list 文件中,只需增加数据库版本。

通过这样做,它创建了新表而不删除/创建我的旧表。

我的版本是1.5

关于android - 没有这样的表 Sugar ORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37091332/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com