public Object execute() throws Exception {
JSONArray result = new JSONArray();
DBHelper dbh = new DBHelper(mContext);
SQLiteDatabase db = dbh.getReadableDatabase();
try{
Cursor cursor_products = db.rawQuery(dbh.GET_ALL_PRODUCTS,null);
//Cursor cursor_products = db.query(DBHelper.PRODUCT_TABLE, new String[]{DBHelper.PRODUCT_ID,DBHelper.PRODUCT_NAME,DBHelper.PRODUCT_PRICE,DBHelper.PRODUCT_QTY}, null, null, null, null, DBHelper.PRODUCT_NAME + " ASC" );
while(cursor_products.moveToNext()){
JSONObject product = new JSONObject();
product.put("id", cursor_products.getInt(0));
product.put("name", cursor_products.getString(1));
product.put("price", cursor_products.getInt(2));
product.put("stock", cursor_products.getInt(3));
result.put(product);
}
cursor_products.close();
}catch(SQLException e){
Log.e(this.getClass().getName()+"@54", e.getMessage());
}finally{
db.close();
dbh.close();
}
return result;
}
使用上面的代码,错误发生在以下行:Cursor cursor_products = db.rawQuery(dbh.GET_ALL_PRODUCTS,null);
这真的很奇怪,因为我确定我的作业是正确的。
它的唯一Eclipse是否有可能无法正确解析代码?
答案 0 :(得分:0)
//试试这个
Cursor cursor_products = db.rawQuery(GET_ALL_PRODUCTS,null);