I'm working on an Android app using zbar to decode QR. The structure of the QR is: "SpecificPrefix/[Number]".
String d = sym.getData(); // I get the QR text from the symbol
if(d.startsWith(QRUri)) { // QRUri is a string const containig the prefix
int id;
try {
Log.d("NOT", "QR Subst \"" + d.substring(QRUri.length()) + "\""); // Print the data after the Prefix
id = Integer.parseInt(d.substring(QRUri.length())); // Try to parse it to int
} catch(NumberFormatException e) {
e.printStackTrace();
id = 0;
}
}
This code worked for every QR so far, but today I found that for "SpecificPrefix/76" it didn't.
This is the log:
D/NOT﹕ QR Subst "76"
D/NOT﹕ No Int found!
W/System.err﹕ java.lang.NumberFormatException: Invalid int: "76"
W/System.err﹕ at java.lang.Integer.invalidInt(Integer.java:138)
W/System.err﹕ at java.lang.Integer.parse(Integer.java:375)
W/System.err﹕ at java.lang.Integer.parseInt(Integer.java:366)
W/System.err﹕ at java.lang.Integer.parseInt(Integer.java:332)
W/System.err﹕ at [...].MainActivity$3.onPreviewFrame(MainActivity.java:146)
W/System.err﹕ at android.hardware.Camera$EventHandler.handleMessage(Camera.java:841)
W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err﹕ at android.os.Looper.loop(Looper.java:137)
W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:4921)
W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:511)
W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
java.lang.NumberFormatException: Invalid int: "76" I can't get why it doesn't work!
Tested on Android 4.1.2 but it seems not to work on 4.4.2 either.
Thanks in advance to anyone hoping to work it out.