gpt4 book ai didi

java - 我将一轮高尔夫球的每洞得分存储在数据库中。我想编写一个函数,对表中的该列求和并显示在 toast 中

转载 作者:行者123 更新时间:2023-12-01 15:24:42 24 4
gpt4 key购买 nike

这是我创建的函数。 Playgolf 表包含 id、holepar、strikes、putts 列。我正在总结这些笔画。

我已经编辑了代码,现在我收到了这个错误......有什么想法吗?

public void DisplaySum(int sum)
{
//Setup a local variable to store sum
int intRoundsSUM = 0;
db.open();
//Setup your database cursor
Cursor c = db.getPLAYGOLF();
Toast.makeText(getBaseContext(), intRoundsSUM, Toast.LENGTH_LONG).show();

//Iterate through the cursor
//Sum up each value
c.moveToFirst();
while(c.isAfterLast() == false) {
intRoundsSUM += c.getInt(2);
c.moveToNext();
}
Toast.makeText(getBaseContext(), intRoundsSUM, Toast.LENGTH_LONG).show();
}
// LOG CAT MAIN ERROR:
//E/AndroidRuntime(597): android.content.res.Resources$NotFoundException: String resource ID #0xa

最佳答案

你必须管理你的光标,从

开始
cursor.moveToFirst();
while(cursor.isAfterLast() == false) {
intRoundsSUM += c.getInt(2);
cursor.moveToNext();
}

另请阅读有关让您的 Activity 使用 activity.startManagingCursor(cursor); 控制光标生命周期的信息

关于java - 我将一轮高尔夫球的每洞得分存储在数据库中。我想编写一个函数,对表中的该列求和并显示在 toast 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10335030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com