I have a file which consists data shown in the image. I need to read this data and pass it to a method which accepts integer values only. So I have to convert this string data into Int. But is shows NumberFormatException.java:65. Please Help. error I got
Asked
Active
Viewed 100 times
-2
-
1Please check [ask]. In particular, post the code (and error) here, with the proper format, so it's easier to view your question. – kabanus Mar 31 '18 at 12:21
-
1And [don't just post image without code](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). – user202729 Mar 31 '18 at 12:23
2 Answers
0
0xF4000000 is a hex string that equals to 4093640704 and it's too large for int. Use Long for converting hex string to number:
Long number = Long.parseLong("F4000000", 16);
Long.parseLong doesn't accept prefix 0x
so you can exclude it:
Long number = Long.parseLong("0xF4000000".replace("0x", ""), 16);

Filomat
- 753
- 1
- 11
- 16
0
use this one to convert hexstring int color code to get a int value from hextstring int color = (Integer.parseInt( hex.substring( 0,2 ), 16) << 24) + Integer.parseInt( hex.substring( 2 ), 16); reference How to convert a color integer to a hex String in Android?