没有这样的表糖ORM

时间:2016-05-07 17:03:29

标签: android sugarorm

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

这是错误:

import math

def egyptian(positive):
    a,b = raw_input('Please input the two numbers separated by a space').split()
a = int(a)
b = int(b)
answer = 0
while b != 0:
    if (a%2 != 0):
        print "B was odd, we add A to make the product: ", (a)
        answer = answer+a
        a = a*2
        b = b//2
    if (b%2 == 0):
        a = A*2
        b = b//2
print "The product of the two numbers is", (answer)


choice = ""
if choice != "y" or "Y":
    choice = raw_input("Do you want to continue?(y/n)")
if choice == "Y" or "y":
    goto NO idea what to put here to get it to loop.        
if choice != "Y" or "y":
    print "Quitting"

我的实体类就是:

    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;
    }
}

我需要帮助,我在每个帖子中都禁用了即时运行选项,但它不起作用。

Settings

感谢您的帮助。

我的机器人清单:

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) {

    }
}

2 个答案:

答案 0 :(得分:3)

可以通过创建一个带有新版本的空“迁移脚本文件”来解决此问题。 这可以通过以下方式完成:

  1. 创建新的Sugar记录类。
  2. 在Android清单文件中只增加数据库版本。
  3. 通过执行此操作,它可以创建新表而不会删​​除/创建旧表。

    我的版本是1.5

答案 1 :(得分:0)

如果您进行数据库修改,则必须删除该应用并安装为新应用或更改数据库版本并编写更改查询。