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