the general use of textbooks, but encountered inexplicable mistakes, Xiaobai can not tell whether it is the conflict between the official and the new version of As and gradle or what is wrong, seek guidance.
the error is as follows:
org.litepal.exceptions.DataSupportException: Attempt to invoke virtual method "java.lang.Class [] java.lang.reflect.Constructor.getParameterTypes ()" on a null object reference
the code is as follows:
public void onClick(View v) {
switch (v.getId()) {
case R.id.create_database:
database = LitePal.getDatabase();
showTable();
break;
case R.id.save_data:
Book book = new Book("think in java", "null", "100");
book.save();
showTable();
break;
default:
break;
}
}
void showTable() {
List<Book> allBooks = DataSupport.findAll(Book.class);
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < allBooks.size(); iPP) {
stringBuffer.append("authorname:" + allBooks.get(i).getAuthorName() + "\n");
stringBuffer.append("bookname:" + allBooks.get(i).getBookName() + "\n");
stringBuffer.append("price:" + allBooks.get(i).getPrice() + "\n");
}
logText.setText(stringBuffer.toString());
}