0
我有一個存儲某些信息的類。我還這個類的對象的數組「點[]」中,所有的信息被正確地添加,但是當我希望有一些這種「點」的信息,例如:無法獲取我自己班級對象列表的正確值
point[1].getId();
我有最後的Id值,但我想要1值。即使「[i]」的值是1或2,或者任何數字,我也只會收到我之前添加的最後一個Id值。我把類代碼和主代碼解釋得更好。
Point類:
public class Point implements java.io.Serializable {
private static final long serialVersionUID = -4910520794768384111L;
String _id;
String _comment;
String _calification;
String _coords;
int _X;
int _Y;
public Point(String id, String comment, String calification, String coords, int x, int y)
{
_id = id;
_comment = comment;
_calification = calification;
_coords = coords;
_X = x;
_Y = y;
}
public String getID()
{
return _id;
}
public String getComment()
{
return _comment;
}
public String getCalification()
{
return _calification;
}
public String getCoords()
{
return _coords;
}
public int getPointX()
{
return _X;
}
public int getPointY()
{
return _Y;
}
}
主類代碼,這裏是我需要的所有信息,我只收到我的Point類信息的最後objetc:
for(int i = 0; i < points.length; i++)
{
try
{
js.put("id",points[i].getID());
js.put("calification",points[i].getCalification());
js.put("comment",points[i].getComment());
js.put("gps",points[i].getCoords());
js.put("X",points[i].getPointX());
js.put("Y",points[i].getPointY());
}
catch (JSONException e)
{
e.printStackTrace();
}
jsPoints.put(js);
}
而且我在類中添加一個值格式的圖像。
有人可以幫我這個問題?我需要爲「我」編號得到正確的值,而不僅僅是最後一個。謝謝!
這不是問題,我想,因爲我把「js」放在JSONArray上:「jsPoints.put(js);」當我看到JSONArray上的值時,它們總是相同的,例如,我有3個具有不同值的點,並且在JSONArray上有三次相同的第三個值,因爲js每次都接收到相同的最後一個值,偶數數字是0或1或2.我添加這部分代碼來幫助你理解我。 – Imrik