Results 1 to 6 of 6
- 04-10-2010, 05:03 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 2
- Rep Power
- 0
Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value
Hi All,
I get this error while I am using parseByte() in my code and it is driving me mad
Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value:"495051" Radix:10
My code is as shown below ...
I am trying to program DICOM's implementation of RLE using Bytes on image files. I tried it using String and works fine but performance is really bad. I am not very comfirtable of using bytes and encouterning many problems.
I am getting the error on this line
rtn_val[array_count]=Byte.parseByte(temp);
Thanks
==
XML Code:public byte[] encodeBytes(byte[] inpByte){ int length=inpByte.length; System.out.println("length "+length); for (int i=0;i<inpByte.length;i++){ System.out.println(inpByte[i]); } //byte[] temp = new byte[length-1]; boolean replicate=false; int d_count=0; int count=0; byte[] rtn_val=new byte[length-1]; int array_count=0; String temp=""; for (count=0;count<length;count++){ System.out.println("in for loop" + inpByte[count]); d_count=1; while(replicate==true && count+1 < length && inpByte[count] == inpByte[count+1]){ d_count++; count++; System.out.println("loop1 "+inpByte[count]); } while(replicate ==false && count+1<length && inpByte[count]!=inpByte[count+1]){ /* int x=0; if(temp==null){ System.out.println("in here"); x=0; }else{ x=temp.length-1; } System.out.println("COUNT " + count +" and inpByte[] " + inpByte[count]); temp[x]=inpByte[count]; */ temp+=inpByte[count]; //Using String instead here to concatenate a run of un-identical byte[] count++; } //if loop if successive elments are identical if(replicate==true){ d_count=((-1*d_count)+1); replicate=false; rtn_val[array_count]=(byte)d_count; array_count++; rtn_val[array_count]=inpByte[count]; array_count++; } //loop here if successive values are not identical if(replicate==false && temp.length()!=0){ d_count=temp.length()-1; rtn_val[array_count]=(byte)d_count; array_count++; System.out.println("22222 " +temp); rtn_val[array_count]=Byte.parseByte(temp); array_count++; temp="";//Now you have the literalRun, set it to null for next iteration replicate=true; count--; //needed to offset the count++ in 2nd while Loop } } return rtn_val; } public static void main(String[] args) throws Exception{ RunLengthEncoding RLE = new RunLengthEncoding(); String example="1%16%22%33%111"; String example2="123111167888321555"; byte[] example3=example2.getBytes(); byte[] byteVal=RLE.encodeBytes(example3);//Leads to error System.out.println("byte vals "+byteVal); }
- 04-10-2010, 05:31 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Byte range from -128 to 127. You cannot hold such a large value in a byte variable.
- 04-10-2010, 10:23 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 2
- Rep Power
- 0
Hi Eranga,
Ok - so what would be your suggestion - ie what should I do?
- 04-12-2010, 04:27 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Set you value in between that range. You may change your implementation.
- 04-12-2010, 11:53 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,467
- Rep Power
- 16
temp+=inpByte[count];
You're concatentaing a load of bytes here for some unknown reason...but this is why you're ending up with an over-large number.
If this is what's actually required then I don't see how you can expect this to be parseable into a byte.
Take the following byte[]...byte[0] = 99, and byte[1] = 12.
That line of code above (if I've read this correctly) will give you a temp of "9912", which you then attempt to turn into a byte.
- 04-12-2010, 03:39 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Separating could be a good solution, based on our OPs' requirement. I'm lazy to go through such a long code. :(
Similar Threads
-
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 6Last Post: 07-16-2009, 03:30 PM -
Exception in thread "main" java.lang.NullPointerException at LinkedList.main(Link
By kavitha_0821 in forum New To JavaReplies: 1Last Post: 07-16-2009, 10:35 AM -
[newbie] Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:
By jon80 in forum New To JavaReplies: 3Last Post: 06-07-2009, 12:14 AM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks