Barcode Numbers too long for Integer.parseInt

懵懂的女人 提交于 2019-12-12 06:38:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!