【发布时间】:2017-05-13 18:43:03
【问题描述】:
遵循文档后,我成功添加了 jar 并实现了示例的代码:
public class Book extends SugarRecord{
String title;
String edition;
public Book(){
}
public Book(String title, String edition){
this.title = title;
this.edition = edition;
}
}
我的主要活动是:
public class MainActivity extends Activity implements View.OnClickListener {
Button btnAdd;
EditText txtedition, txttitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnAdd = (Button) findViewById(R.id.btnadd);
btnAdd.setOnClickListener(this);
txtedition = (EditText) findViewById(R.id.txtedition);
txttitle = (EditText) findViewById(R.id.txttitle);
}
@Override
public void onClick(View v) {
String edition = txtedition.getText().toString();
String title = txttitle.getText().toString();
switch (v.getId()) {
case R.id.btnadd:
Book book = new Book(title, edition);
book.save();
break;
}
}
}
我的应用程序构建成功,但是当我按下添加按钮时出现以下异常:
致命异常:主要 进程:com.example.agds.demo,PID:7939 android.database.sqlite.SQLiteException: no such table: BOOK (code 1): , while compile: INSERT OR REPLACE INTO BOOK(TITLE,ID,EDITION) VALUES (?,?,?) ################################################# ############### 错误代码:1(SQLITE_ERROR) 原因:SQL(查询)错误或缺少数据库。 (没有这样的表:BOOK(代码1):,编译时:INSERT OR REPLACE INTO BOOK(TITLE,ID,EDITION) VALUES (?,?,?)) ################################################# ############### 在 android.database.sqlite.SQLiteConnection.nativePrepareStatement(本机方法) 在 android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1058) 在 android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:623) 在 android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 在 android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:59) 在 android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31) 在 android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1607) 在 com.orm.SugarRecord.save(SugarRecord.java:266) 在 com.orm.SugarRecord.save(SugarRecord.java:360) 在 com.example.agds.demo.MainActivity.onClick(MainActivity.java:49) 在 android.view.View.performClick(View.java:5702) 在 android.widget.TextView.performClick(TextView.java:10888) 在 android.view.View$PerformClick.run(View.java:22541) 在 android.os.Handler.handleCallback(Handler.java:739) 在 android.os.Handler.dispatchMessage(Handler.java:95) 在 android.os.Looper.loop(Looper.java:158) 在 android.app.ActivityThread.main(ActivityThread.java:7229) 在 java.lang.reflect.Method.invoke(本机方法) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
有什么建议吗?
【问题讨论】:
标签: android sqlite orm sugarorm