问题
im using zbar for barcode services, and at certain numbers the app shutsdown.
Im scanning barcodes, receive the barcode in an edittext, have it set up so it would search the json array for matching id's. Well this works fine for normal numbers the way that Integers extend to.. However i have a need to have it accept what ever value it contains.
Also when using breakpoints like 000.000.000.0
and 22-22ON
the app shuts down.
Does anyone have a clue on how to avoid this?
Is it possible to have it check for anything that is typed in?
Have looked at different snippets and tutorials, but cant find an answer..
String xyz = edt.getText().toString();
try { // Getting JSON Array
user = json.getJSONArray(TAG_FIXTURE);
JSONObject c = user.getJSONObject(Integer.parseInt(xyz)-1);
回答1:
Integer.parseInt(value) requires the String to only contain numbers.
If you look here the poster has a similar problem. Get int from String, also containing letters, in Java
Alternatively you could try simply using a String and try to match with that, if it is possible that the IDs like "22-22ON" are present in the database you're searching in.
来源:https://stackoverflow.com/questions/26464017/barcode-numbers-too-long-for-integer-parseint