Hi,
I looked for an answer but it seems I am the only one to have this problem.
My goal is to create some objects parsing a text file(that should be inside the jar/apk/ipa package for distribution purpose) to pass arguments to the constructor; this is what I do:
private void createObjects() {
String[] stringhe = new String[4];
splashPrint("...init InputStream...");//set txt to a Label by Display.getInstance().callSeriallyAndWait(R)
InputStream objList = Display.getInstance().getResourceAsStream(InputStream.class, "/objs");
splashPrint("...init Reader...");
InputStreamReader isr = new InputStreamReader(objList);
splashPrint("...read from InputStream...");
for(int i = 0; i < objs.length; i++){
for (int j = 0; j < stringhe.length; j++) {
splashPrint("...try reading String[" + i + "][" + j + "]...");
StringBuffer sb = new StringBuffer();
boolean separator = false;
while (!separator) {
try {
char c = (char) isr.read();
if(c == '#'){
while(c != '\n'){
c = (char) isr.read();
}
c = (char) isr.read();
}
if (c == ',' || c == '\n' || c == '\u001a') {
separator = true;
} else {
sb.append(c);
}
} catch (IOException e) {
e.printStackTrace();
}
}
stringhe[j] = sb.toString();
splashPrint("...finish reading String[" + i + "][" + j + "]...");
}
splashPrint("...loading Image...");
Image immagine = null;
try {
if (stringhe[2].equals("0")) {
immagine = Image.createImage("/" + stringhe[0]
+ stringhe[1] + ".png");
}else if (stringhe[2].equals("1")){
immagine = Image.createImage("/" + stringhe[0]
+ stringhe[1] + "m" + ".png");
}else {
immagine = Image.createImage("/" + stringhe[0]
+ stringhe[1] + "f" + ".png");
}
} catch (IOException e) {
e.printStackTrace();
Display.getInstance().exitApplication();
}
splashPrint("...building " + i + " - ...");
objs[i] = new Obj(stringhe[0], stringhe[1], Integer.parseInt(stringhe[2]), Boolean.parseBoolean(stringhe[3]), immagine);
splashPrint("...building " + i + " - " + objs[i].toString() + "DONE!");
}
try {
isr.close();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
objList.close();
} catch (IOException e) {
e.printStackTrace();
}
}
In simulator and android2.3, everything works fine while my iPod Touch 4g(iOS 6.1.3) stops showing me
"...init InputStream..."
on the debug Label and a Dialog in which compare a message about a java.util.NoSuchElementException.
The strange thing is that if I substitute the file parsing with an array of String, everything works well, even the Image loading, so I suppose there is something wrong when I try to create the input stream from the file.
Many thanks in advance.