My switch statement isn't working as whole.
I have never used switch in Java, and I dont know what I did wrong. It is also not executing default. I looked some info up about switch statements, and I think maybe it is because of this line:
if (pair.length == 2) {
// Voorbeeld van het gebruik van de key/value pairs
switch (pair[0]) {
because what I looked up it looked like everybody was using a variable on the pair[0] spot.
Thanks in advance!
String scanString = result.getText(); // result.getText();
String[] parts = scanString.split("\\||");
// Loop alle delen tussen | langs
for (String part : parts) {
String[] pair = part.split("\\|"); // Bevat de key en value pair voor en na het streepje
if (pair.length == 2) {
// Voorbeeld van het gebruik van de key/value pairs
switch (pair[0]) {
case "po":
System.out.println("Productieorder: " + pair[1]);
edt2.setText(pair[1]);
break;
case "tnr":
System.out.println("Tekeningnummer: " + pair[1]);
break;
case "ref":
System.out.println("Referentie: " + pair[1]);
break;
case "hafa":
System.out.println("Half Fabrikaat: " + pair[1]);
break;
case "art":
System.out.println("Artikel: " + pair[1]);
break;
case "atl":
System.out.println("Aantal: " + pair[1]);
break;
case "loc":
System.out.println("Locatie: " + pair[1]);
edt4.setText(pair[1]);
break;
default:
System.out.println("NIET GELUKT");
}
}
}
Edit
I Will try simply this: if (pair.length > 2) instead of == 2, I acually don't even know why it was == 2, because I need to scan qr string that can exist out of more than 3000 chars.
pair.lengthat that point? `switchstatement works fine in IdeOne: ideone.com/7Cxxm7 . It's probably the value ofpair.length. Step through it with the debugger, or print its value in the log (log.i, see here ). Then you'll know for certain.