Android复选框求和代码,在android中的sqlite中求和

我是

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();

}

}

如果详细解释,因为我是一个完整的菜鸟,我会尝试找到解决方案,但没有找到任何东西会有所帮助.谢谢提前

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 to start activity ComponentInfo{com.hishighness.budgetracker/com.hishighness.budgetracker.TransactionReport}: java.lang.NullPointerException

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.ActivityThread.access$1500(ActivityThread.java:117)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.os.Handler.dispatchMessage(Handler.java:99)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.os.Looper.loop(Looper.java:130)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.ActivityThread.main(ActivityThread.java:3687)

10-10 03:55:29.828: E/AndroidRuntime(10229): at java.lang.reflect.Method.invokeNative(Native Method)

10-10 03:55:29.828: E/AndroidRuntime(10229): at java.lang.reflect.Method.invoke(Method.java:507)

10-10 03:55:29.828: E/AndroidRuntime(10229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)

10-10 03:55:29.828: E/AndroidRuntime(10229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)

10-10 03:55:29.828: E/AndroidRuntime(10229): at dalvik.system.NativeStart.main(Native Method)

10-10 03:55:29.828: E/AndroidRuntime(10229): Caused by: java.lang.NullPointerException

10-10 03:55:29.828: E/AndroidRuntime(10229): at com.hishighness.budgetracker.TransactionReport.onCreate(TransactionReport.java:27)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

10-10 03:55:29.828: E/AndroidRuntime(10229): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

10-10 03:55:29.828: E/AndroidRuntime(10229): ... 11 more

这是日志.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值