Results 1 to 6 of 6
  1. #1
    jav2000x is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Angry 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); 
                 	}

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    jav2000x is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default

    Hi Eranga,

    Ok - so what would be your suggestion - ie what should I do?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    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.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  2. Replies: 6
    Last Post: 07-16-2009, 03:30 PM
  3. Replies: 1
    Last Post: 07-16-2009, 10:35 AM
  4. Replies: 3
    Last Post: 06-07-2009, 12:14 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •