gpt4 book ai didi

java - 比较整数的奇怪错误

转载 作者:行者123 更新时间:2023-11-29 20:45:40 25 4
gpt4 key购买 nike

<分区>

我有一个奇怪的奇怪的奇怪的奇怪的错误,首先是给我错误的类

public class SpeciePesci {


public static final SpeciePesce[] specie = (new SpeciePesce[]{
new SpeciePesce(13,"Trota fario", R.drawable.specie_trota_fario, R.string.specie_descrizione_trota_fario),
new SpeciePesce(14,"Trota iridea", R.drawable.specie_trota_iridea, R.string.specie_descrizione_trota_iridea),
new SpeciePesce(4,"Trota marmorata", R.drawable.specie_trota_marmorata, R.string.specie_descrizione_trota_marmorata),
new SpeciePesce(15,"Trota lacustre", R.drawable.specie_trota_lacustre, R.string.specie_descrizione_trota_lacustre),
new SpeciePesce(195,"Salmerino alpino", R.drawable.specie_salmerino_alpino, R.string.specie_descrizione_salmerino_alpino),
new SpeciePesce(18,"Salmerino di fonte", R.drawable.specie_salmerino_fonte, R.string.specie_descrizione_salmerino_fonte),
new SpeciePesce(19,"Carpa", R.drawable.specie_carpa, R.string.specie_descrizione_carpa),
new SpeciePesce(20,"Tinca", R.drawable.specie_tinca, R.string.specie_descrizione_tinca),
new SpeciePesce(16,"Temolo", R.drawable.specie_temolo, R.string.specie_descrizione_temolo),
new SpeciePesce(22,"Persico reale", R.drawable.specie_persico_reale, R.string.specie_descrizione_persico_reale),
new SpeciePesce(21,"Lucio", R.drawable.specie_lucio, R.string.specie_descrizione_lucio)
});


public static Integer getPosition(Integer id){
Integer pos= -1;
if(195==195){
Log.d("INT==","195==195 ?? OK");

}
if(id==195){
Log.d("INT==","ID==195 ?? OK");

}
for (int i = 0; i < specie.length; i++) {
if(specie[i].getId()==195){
Log.d("INT==","getID==195 ?? OK");

}
Log.d("INT==",""+specie[i].getId()+"=="+id);
if (specie[i].getId()==id ) {
Log.d("INT==","OK");
pos = i;
break;
}
}
return pos;
}
}

和其他类

public class SpeciePesce {
private Integer id;
private String title;
private Integer resourceImage;
private Integer resourceDescription;

public SpeciePesce(Integer id, String title, Integer resourceImage, Integer resourceDescription) {
this.id = id;
this.title = title;
this.resourceImage = resourceImage;
this.resourceDescription = resourceDescription;
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public Integer getResourceImage() {
return resourceImage;
}

public void setResourceImage(Integer resourceImage) {
this.resourceImage = resourceImage;
}

public Integer getResourceDescription() {
return resourceDescription;
}

public void setResourceDescription(Integer resourceDescription) {
this.resourceDescription = resourceDescription;
}
}

当我调用方法 getPosition(X) 时,假设我收到了具有此类 ID 的项目在数组中的位置;直到这里它都很简单,它适用于除 195 以外的所有 ID。当它比较 195==195 时,它给了我 false.. 可以是什么??

我确实记录了各种案例..这里是结果

05-23 14:30:28.665      560-560/com.evosw.altosarca D/INT==﹕ 195==195  ?? OK
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ ID==195 ?? OK
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 13==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 14==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 4==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 15==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ getID==195 ?? OK
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 195==195 << suppose the loop stop here
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 18==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 19==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 20==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 16==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 22==195
05-23 14:30:28.665 560-560/com.evosw.altosarca D/INT==﹕ 21==195

这是一个工作的例子

05-23 14:35:30.068    3153-3153/com.evosw.altosarca D/INT==﹕ 195==195  ?? OK
05-23 14:35:30.068 3153-3153/com.evosw.altosarca D/INT==﹕ 13==13
05-23 14:35:30.068 3153-3153/com.evosw.altosarca D/INT==﹕ OK
05-23 14:35:30.103 3153-3153/com.evosw.altosarca D/INT==﹕ 195==195 ?? OK
05-23 14:35:30.103 3153-3153/com.evosw.altosarca D/INT==﹕ 13==13
05-23 14:35:30.103 3153-3153/com.evosw.altosarca D/INT==﹕ OK
05-23 14:35:30.103 3153-3153/com.evosw.altosarca D/INT==﹕ 195==195 ?? OK
05-23 14:35:30.103 3153-3153/com.evosw.altosarca D/INT==﹕ 13==13
05-23 14:35:30.103 3153-3153/com.evosw.altosarca D/INT==﹕ OK

可以是什么? :S

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