我正在尝试打印获取并存储在对象中的数据集。该对象使用一个数组列表。在获取数据时(在将其添加到数组列表之前),所有记录都打印不同,但是当我开始打印它们时,它们是相同的。我不知道为什么。
这是代码
void caseClicked()
{
//println("Inside case clicked");
for(int i = 0; i < mapData.size(); i++)
{
if (dist(mapData.get(i).pf.x, mapData.get(i).pf.y, gX, gY) < percentY(1))
{
clickedCaseId = mapData.get(i).icaseNum;
clickedStateId = mapData.get(i).stateId;
glyphPosX = mapData.get(i).pf.x;
glyphPosY = mapData.get(i).pf.y;
print("Value of icaseNum selected" + mapData.get(i).icaseNum + "\n");
break;
}
else
continue;
}
try{
db.getConnection();
if (db.conn.connect())
{
String tempQ = "select distinct(svin), vfatcount, saccdate, day " + d_year + " where icasenum = " + clickedCaseId + " and istatenum = " + clickedStateId;
println(tempQ);
db.conn.query(tempQ);
Glyph tg1 = new Glyph();
gl.fnVins.clear();
while (db.conn.next())
{
tg1.fVin.VIN = db.conn.getString(1);
tg1.fVin.fatals = (int)Float.parseFloat(db.conn.getString(2));
println("Value of VIN is " + tg1.fVin.VIN + "\n");
println("Value of fatals is " + tg1.fVin.fatals + "\n");
gl.fnVins.add(tg1.fVin);
gl.gdate = db.conn.getString(3);
gl.gday = db.conn.getString(4);
}
for (int i = 0; i < gl.fnVins.size(); i++)
println("Value of VIN is " + gl.fnVins.get(i).VIN + "\n");
}
}
catch (Exception e)
{
System.err.println ("Error:DBHelper.dataPointQuery - " + e.toString());
// return null;
}
db.closeConnection();
}
字形类是
public class Glyph
{
float caseNum = 0;
float stateId = 0;
float time = 0;
int fatal = 0;
String gday = "", gdate = "";
class fnVin
{
int fatals = 0;
String VIN = "";
}
fnVin fVin = new fnVin();
ArrayList<fnVin> fnVins = new ArrayList<fnVin>();
}
请有人能帮我弄清楚这个实现有什么问题吗?提前致谢。