尝试通过 SugarORM 将数据保存到数据库
Trying to save data to Database by SugarORM
按照官网说明,尝试用SugarOrm将Book存入数据库
public class MainActivity extends AppCompatActivity {
Button btnSave;
EditText title;
EditText title2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
title = findViewById(R.id.e1);
title2 = findViewById(R.id.e2);
btnSave = findViewById(R.id.b1);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String temporatyTitle = title.getText().toString();
String temporaryEdition = title2.getText().toString();
Book book = new Book(temporatyTitle, temporaryEdition);
book.save();
}
});
}
}
2级
public class Book extends SugarRecord<Book> {
String title;
String edition;
public Book(){
}
public Book(String title, String edition){
this.title = title;
this.edition = edition;
}
}
我收到错误
no such table: BOOK
如何创建这个 table?我在官网上找不到这个
如果您已按照文档中的建议完全设置清单文件。尝试将您的数据库版本号更改为更高的值
按照官网说明,尝试用SugarOrm将Book存入数据库
public class MainActivity extends AppCompatActivity {
Button btnSave;
EditText title;
EditText title2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
title = findViewById(R.id.e1);
title2 = findViewById(R.id.e2);
btnSave = findViewById(R.id.b1);
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String temporatyTitle = title.getText().toString();
String temporaryEdition = title2.getText().toString();
Book book = new Book(temporatyTitle, temporaryEdition);
book.save();
}
});
}
}
2级
public class Book extends SugarRecord<Book> {
String title;
String edition;
public Book(){
}
public Book(String title, String edition){
this.title = title;
this.edition = edition;
}
}
我收到错误
no such table: BOOK
如何创建这个 table?我在官网上找不到这个
如果您已按照文档中的建议完全设置清单文件。尝试将您的数据库版本号更改为更高的值