我正在用数据库中的多个表创建一个android应用程序。因此,我有两个分别名为“供应商”和“客户”的按钮。我可以在“客户”活动上正确执行数据库操作,但是当我单击“供应商”按钮时,它崩溃了。这是error image。
我尝试交叉检查每行代码,并且也交叉检查以查看是否忘记了.xml与.java的链接。
VendorBaramatiDBHelper.java
public List getAllVendorsBaramati() {
List vendorsbaramatiDetailsList = new ArrayList();
String selectQuery = "SELECT * FROM " + TABLE_NAME
+ " ORDER BY " + KEY_VENDORBARAMATI_ID + " DESC";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
//if TABLE has rows
if (cursor.moveToFirst()) {
//Loop through the table rows
do {
BaramatiVendorsDetails baramatiVendorsDetails = new BaramatiVendorsDetails();
baramatiVendorsDetails.setVendorIdbaramati(cursor.getInt(0));
baramatiVendorsDetails.setVendorNamebaramati(cursor.getString(1));
baramatiVendorsDetails.setProductNameVendorbaramati(cursor.getString(2));
baramatiVendorsDetails.setQuantityVendorbaramati(cursor.getInt(3));
baramatiVendorsDetails.setRateVendorbaramati(cursor.getInt(4));
baramatiVendorsDetails.setTotalpriceVendorbaramati(cursor.getInt(5));
baramatiVendorsDetails.setPaidVendorbaramati(cursor.getInt(6));
baramatiVendorsDetails.setUnpaidVendorbaramati(cursor.getInt(7));
//Add movie details to list
vendorsbaramatiDetailsList.add(baramatiVendorsDetails);
} while (cursor.moveToNext());
}
db.close();
return vendorsbaramatiDetailsList;
}
VendrosOFbaramati.java
private void populateSpinnerVendorbaramati() {
List<BaramatiVendorsDetails> baramatiVendorsDetailsList =vendorBaramatiDBHelper.getAllVendorsBaramati();
List<VendorSpinnerVO> vendorbaramatiSpinnerList = new ArrayList<>();
for (int i = 0; i < baramatiVendorsDetailsList.size(); i++) {
BaramatiVendorsDetails movieDetailsVO = baramatiVendorsDetailsList.get(i);
VendorSpinnerVO movieSpinnerVO = new VendorSpinnerVO(movieDetailsVO.getVendorIdbaramati(),
movieDetailsVO.getVendorNamebaramati());
vendorbaramatiSpinnerList.add(movieSpinnerVO);
}
if (baramatiVendorsDetailsList.size() == 0) {
LinearLayout displayArea = (LinearLayout) findViewById(R.id.displayArea);
displayArea.setVisibility(LinearLayout.GONE);
LinearLayout editButton = (LinearLayout) findViewById(R.id.editButton);
editButton.setVisibility(LinearLayout.GONE);
LinearLayout editArea = (LinearLayout) findViewById(R.id.editArea);
editArea.setVisibility(LinearLayout.GONE);
LinearLayout movieSpinnerLayout = (LinearLayout) findViewById(R.id.movieSpinnerLayout);
movieSpinnerLayout.setVisibility(LinearLayout.GONE);
} else {
LinearLayout movieSpinnerLayout = (LinearLayout) findViewById(R.id.movieSpinnerLayout);
movieSpinnerLayout.setVisibility(LinearLayout.VISIBLE);
}
我想存储供应商详细信息,并且还执行其他数据库操作。但实际上它崩溃了。