我正在尝试为计费系统创建一个应用程序。这些值被插入到数据库中并成功检索。另外,我需要数据库中的总金额。
数据库辅助类
public Cursor gettotal()
{
SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor =database.rawQuery("select * from '"+PRODUCTS+"' ;", null);
Log.d(TAG, "gettotal: "+cursor.getCount());
return cursor;
}
总计
private void getTotal() {
int m=0;
Cursor cursor = db.gettotal();
if(cursor.getCount()==0)
{
Toast.makeText(getApplicationContext(),"No message is available", Toast.LENGTH_LONG).show();
}
else
{
for(int k = 0; k<=cursor.getCount();k++) {
m += (int) Integer.parseInt(String.valueOf(cursor.getColumnIndex("amount")));
}
i=m;
total_amount.setText(m);
}
}
我的日志猫
D/MainActivity: getTotal: -1
E/uetooth_embade: Invalid ID 0x00000008.
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.bluetooth_embaded, PID: 14063
android.content.res.Resources$NotFoundException: String resource ID #0x8
at android.content.res.Resources.getText(Resources.java:360)
at android.content.res.MiuiResources.getText(MiuiResources.java:97)
at android.widget.TextView.setText(TextView.java:5837)
at com.example.bluetooth_embaded.MainActivity.getTotal(MainActivity.java:100)
at com.example.bluetooth_embaded.MainActivity.access$200(MainActivity.java:33)
at com.example.bluetooth_embaded.MainActivity$5.onClick(MainActivity.java:181)
at android.view.View.performClick(View.java:6616)
at android.view.View.performClickInternal(View.java:6593)
at android.view.View.access$3100(View.java:785)
I/Process: Sending signal. PID: 14063 SIG: 9
一只名叫tom的猫
相关分类