0
I have a code that adds certain values to a list of Strings but it seems that when I convert them to float later to String again they are not added! What’s the matter ?
Code in which they are added :
if(media.size()!=0){
medias.add(media.get(media.size()-1).text());
}
Code in which they are not added :
if(media.size()!=0){
Float media_float = Float.valueOf(media.get(media.size()-1).text());
media_float = media_float /10;
String media_string = String.valueOf(media_float);
medias.add(media_string);
}
Here is the complete code :
Thread t1 = new Thread() {
@Override
public void run() {
try {
String site1 = "http://www.dges.gov.pt/guias/indcurso.asp?letra=";
Document document;
Elements lista;
document = Jsoup.connect(site1 +letra_value).get();
Elements boxes = document.select("div.box10");
for (Element box : boxes) {
String linAreaC1 = box.select(".lin-area-c1").text();
String linAreaC2 = box.select(".lin-area-c2").text();
String linAreaC3 = box.select(".lin-area-c3").text();
codigoCurso.add(linAreaC1);
curso.add(linAreaC2);
Element linCurso = box.nextElementSibling();
while (linCurso.hasClass("lin-curso")) {
String linCursoC2 = linCurso.select(".lin-curso-c2").text();
String linCursoC3 = linCurso.select(".lin-curso-c3").text();
String linCursoC4 = linCurso.select(".lin-curso-c4").text();
codigoFaculdade.add(linCursoC2);
faculades.add(linCursoC3);
linCurso = linCurso.nextElementSibling();
}
faculades_main.add(faculades);
faculades = new ArrayList<String>();
codigosFaculdade.add(codigoFaculdade);
codigoFaculdade= new ArrayList<String>();
}
for(int contador=0;contador<faculades_main.size();contador++){
String codigoFaculdadi;
String codigoCursi;
codigoCursi = codigoCurso.get(contador);
for(int i=0;i<codigosFaculdade.get(contador).size();i++){
codigoFaculdadi=codigosFaculdade.get(contador).get(i);
String site = "http://www.dges.gov.pt/guias/detcursopi.asp?codc="+codigoCursi+"&code="+codigoFaculdadi;
Document document1 = Jsoup.connect(site).get();
Elements media = document1.select(".tvag");
if(media.size()!=0){
medias.add(media.get(media.size()-1).text());
}else {
medias.add("N/A");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
prepareListData();
}
};
I did a test and it worked perfectly your example, are you sure the variable
media_float
is being filled correctly?– Paulo H. Hartmann
Yes the way I said in the first example of , but in the second no , I do not understand
– Junkrat
If you want I can post the whole code
– Junkrat
Do this, edit your post please show us where you create this structure
media
and where it is filled– Paulo H. Hartmann
Elements is a structure you implemented?
– André Ozawa
Are you sure the String variable is not getting null?
– GabrielLocalhost