我是java,android和sqlite的新手,我坚持这个.我有列_id,type,amount(int),category,description.我正在尝试获取特定类别的金额总和并将它们存储在int中.我知道我需要提供错误,但它只是给我力量关闭.请帮助
public class TransactionReport extends Activity {
private static SQLiteDatabase db;
Cursor c;
int amount;
DbCrud localDbCrud = new DbCrud(this);
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.report);
localDbCrud.open(); //localDatabase = localDbHelper.getWritableDatabase(); return this;
c.moveToFirst();
do{
c = db.rawQuery("select sum(amount) from transaction_table where category = Salary ;", null);
}while(c.moveToNext());
amount = c.getInt(0);
c.close();
TextView ltxt = (TextView) findViewById(R.id.amt);
ltxt.setText(""+amount);
localDbCrud.close(); //localDatabase.close();
}
}
Run Code Online (Sandbox Code Playgroud)
如果详细解释,因为我是一个完整的菜鸟,我会尝试找到解决方案,但没有找到任何东西会有所帮助.谢谢提前
10-10 03:55:29.828: E/AndroidRuntime(10229): FATAL EXCEPTION: main
10-10 03:55:29.828: E/AndroidRuntime(10229): java.lang.RuntimeException: Unable …Run Code Online (Sandbox Code Playgroud)