JavaRanch » Java Forums »
Java »
Beginning Java
| Author |
incompatible types: found double required float error;
|
anitha vani
Greenhorn
Joined: Jun 08, 2009
Posts: 6
|
|
//The alignment of the features is assumed to be AVG, VAR, CSD, GABOR
I'm hoping this is the right place for posting my question. This is the error I'm getting in my code...
ani@ani-desktop:~/Desktop/executedfiles$ javac retrievalGabor.java
retrievalGabor.java:54: incompatible types
found : double[]
required: float[]
query= new double[]
{0.1544465f ,0.54298925f ,0.73340774f ,0.017640665f ,0.085013896f ,0.095653236f ,
0.0 ,0.4047619f ,0.36394557f ,0.21768707f ,0.09863946f ,0.088435374f ,0.08163265f ,0.06462585f ,
0.05782313f ,0.27210885f ,0.26870748f ,0.10204082f ,0.0 ,0.010204081f ,0.0034013605f ,0.0 ,0.0 ,0.0 ,
0.0 ,0.0 ,0.0 ,0.023809524f ,0.010204081f ,0.0 ,0.0 ,0.17687075f ,0.32312927f ,0.0 ,0.0 ,0.09863946f ,
0.6632653f ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.013605442f ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,
0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,
0.0 ,0.08163265f ,0.0 ,0.0 ,0.0 ,0.49659863f ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.010204081f ,0.0 ,0.0 ,0.0 ,
0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,
0.0 ,0.0 ,0.0 ,0.0 ,0.0 ,0.0};
^
1 error
java code here:
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
The error message seems really clear to me. The query variable is a float array -- and you tried to assign an double array to it.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Anitha: Please Use Code tag to post your code.so that it can be easy to read
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Henry Wong wrote:The error message seems really clear to me. The query variable is a float array -- and you tried to assign an double array to it.
Correct. You should change the assignment to new float[]. That still would not compile because of the 0.0's - those are doubles. If you change those to 0.0f they become floats and the array can hold them.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
seetharaman venkatasamy wrote:Anitha: Please Use Code tag to post your code.so that it can be easy to read
Agree. And don't use pale green text; it is hard to read. And don't use such long lines; they are hard to read.
|
 |
Junior Zhang
Greenhorn
Joined: Feb 01, 2008
Posts: 6
|
|
Your declaration:
is not consistent with your assignment:
|
 |
anitha vani
Greenhorn
Joined: Jun 08, 2009
Posts: 6
|
|
thanks for the help i tried using float ,it got compiled but for running i got the following error.I am doing my java program in linux .Can anyone help me with this error?
ani@ani-desktop:~/Desktop/myUtilities/UTILITIESR$ java retrievalGabor 0000.jpg gabor_representative feat_representative.txt out0.txt 1 ppk.txt.txt wy
java.lang.ArrayIndexOutOfBoundsException: 126
at retrievalGabor.main(retrievalGabor.java:57)
java code here
//The alignment of the features is assumed to be AVG, VAR, CSD, GABOR
import java.io.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.image.*;
class retrievalGabor
{
public static void main(String args[])
{
if(args.length!=6 && args.length!=7)
{
System.out.println("The parameters are {Query Image} {Query Gabor file} {Features File} {Gabor Text File} [blocks] {Relevant Features} {EPS directory}");
System.exit(0);
}
int BLOCKS=1, FEATURES=15, SCALE=3, ORIENTATION=4;
BufferedImage bi, bi1;
GraphicsEnvironment ge= GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd=ge.getDefaultScreenDevice();
GraphicsConfiguration gc=gd.getDefaultConfiguration();
Graphics2D g2D=null;
ColorModel cm=null;
DataInputStream dis, dis1;
BufferedReader br, br1;
float features[][], diff[], query[], tmp=0;
String names[], tmps=null, tokens[];
int images=0, wt[], bitcount=0;
char ch;
try{
bi=ImageIO.read(new File(args[0]));
bi1=gc.createCompatibleImage(bi.getWidth(null), bi.getHeight(null));
g2D=bi1.createGraphics();
g2D.drawImage(bi, null, 0, 0);
bi=bi1;
dis=new DataInputStream(new FileInputStream(args[2]));//opening the features file
br=new BufferedReader(new FileReader(args[3]));//opening the texture features file
if(args.length==7)
{
BLOCKS=Integer.parseInt(args[4]);
dis1=new DataInputStream(new FileInputStream(args[5]));//opening the relevant features file
}
else
dis1=new DataInputStream(new FileInputStream(args[4]));//opening the relevant features file
//query=myFinalToolkit.computeColorSampleImage(bi, BLOCKS, SCALE*ORIENTATION);
query= new float[] {0.1544465f ,0.54298925f ,0.73340774f ,0.017640665f ,0.085013896f ,0.095653236f ,0.0f ,0.4047619f ,0.36394557f ,0.21768707f ,0.09863946f ,0.088435374f ,0.08163265f ,0.06462585f ,0.05782313f ,0.27210885f ,0.26870748f ,0.10204082f ,0.0f ,0.010204081f ,0.0034013605f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.023809524f ,0.010204081f ,0.0f ,0.0f ,0.17687075f ,0.32312927f ,0.0f ,0.0f ,0.09863946f ,0.6632653f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f,0.013605442f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f,0.0f ,0.0f ,0.0f,0.0f ,0.0f ,0.0f,0.0f,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f,0.0f ,0.0f,0.0f ,0.0f,0.08163265f ,0.0f ,0.0f ,0.0f ,0.49659863f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f,0.010204081f,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f,0.0f ,0.0f,0.0f ,0.0f ,0.0f,0.0f,0.0f, 0.0f ,0.0f,0.0f ,0.0f ,0.0f ,0.0f ,0.0f ,0.0f,0.0f,0.0f,0.0f ,0.0f ,0.0f,0.0f ,0.0f ,0.0f};
br1=new BufferedReader(new FileReader(args[1]));//opening the Query texture file
tokens=(br1.readLine()).split(" ");
for(int i=3;i<2*BLOCKS*SCALE*ORIENTATION;i++)
query[BLOCKS*6+120+i-3]=Float.parseFloat(tokens[i]);
br1.close();
//reading the features file
images=dis.readInt();
features=new float[images][BLOCKS*(6+SCALE*ORIENTATION*2)+120];
names=new String[images];
for(int i=0;i<images;i++)
{
names[i]=new String();
while((ch=dis.readChar())!='\n')
names[i]+=ch;
for(int j=0; j<BLOCKS*6+120;j++)
features[i][j]=dis.readFloat();
dis.readChar();
tokens=(br.readLine()).split(" ");
for(int j=3;j<BLOCKS*2*SCALE*ORIENTATION;j++)
features[i][BLOCKS*6+120+j-3]=Float.parseFloat(tokens[j]);
}
dis.close();
br.close();
//reading the feature relevancy
wt=new int[BLOCKS*(FEATURES-1)+1];
for(int i=0;i<BLOCKS*(FEATURES-1)+1;i++)
{
wt[i]=dis1.readInt();
System.out.print(wt[i]+" ");
}
System.out.println();
dis1.close();
diff=new float[images];
for(int i=0;i<images;i++)
{
//average and variance in color
for(int j=0;j<BLOCKS;j++)
{
for(int k=0;k<2;k++)
{
tmp=0;
if(wt[j*(FEATURES-1)+k]==1)
{
for(int l=0;l<3;l++)
tmp+=Math.abs(query[j*6+k*3+l]-features[i][j*6+k*3+l]);
diff[i]+=tmp/3;
}
}
}
//CSD
tmp=0;
if(wt[BLOCKS*(FEATURES-1)]==1)
{
for(int k=0;k<120;k++)
tmp+=Math.abs(query[BLOCKS*6+k]-features[i][BLOCKS*6+k]);
diff[i]+=tmp/120;
}
//texture features
for(int j=0;j<BLOCKS;j++)
for(int k=0;k<SCALE*ORIENTATION;k++)
{
tmp=0;
if(wt[j*(FEATURES-1)+2+k]==1)
for(int l=0;l<2;l++)
{
tmp+=Math.abs(query[BLOCKS*6+120+j*SCALE*ORIENTATION+2*k+l]-features[i][BLOCKS*6+120+j*SCALE*ORIENTATION+2*k+l]);
}
diff[i]+=tmp/2;
}
}
//sort the entries in the sorted order
for(int i=0;i<images-1;i++)
for(int j=0;j<images-i-1;j++)
{
if(diff[j+1]<diff[j])
{
tmp=diff[j];
diff[j]=diff[j+1];
diff[j+1]=tmp;
tmps=names[j];
names[j]=names[j+1];
names[j+1]=tmps;
tmps=null;
}
}
/* //sort the entries in the sorted order by name
for(int i=0;i<29;i++)
for(int j=0;j<29-i;j++)
{
if(names[j].compareTo(names[j+1])>0)
{
tmp=diff[j];
diff[j]=diff[j+1];
diff[j+1]=tmp;
tmps=names[j];
names[j]=names[j+1];
names[j+1]=tmps;
tmps=null;
}
}
*/
Runtime rt=Runtime.getRuntime();
String arr[]=new String[3], dir[]=new String[2];
dir[0]=new String("/bin/mkdir");
if(args.length==6)
dir[1]=new String("/tmp/"+args[5]+args[0].substring(args[0].lastIndexOf('/')+1, args[0].lastIndexOf('.')));
else
dir[1]=new String("/tmp/"+args[6]+args[0].substring(args[0].lastIndexOf('/')+1, args[0].lastIndexOf('.')));
rt.exec(dir);
arr[0]=new String("/bin/cp");
for(int i=0;i<30;i++)
{
System.out.println(names[i]+" "+diff[i]);
arr[1]=new String(args[0].substring(0,args[0].lastIndexOf("/")+1)+names[i]);
if(i<10)
arr[2]=new String(dir[1]+"/0"+i+".jpg");
else
arr[2]=new String(dir[1]+"/"+i+".jpg");
rt.exec(arr);
}
}
catch(Exception e)
{
e.printStackTrace();
System.exit(0);
}
}
}
|
 |
Junior Zhang
Greenhorn
Joined: Feb 01, 2008
Posts: 6
|
|
Please check Line 57. You may use an index, whose value is bigger than max index of the array.
For example:
|
 |
 |
|
|
subject: incompatible types: found double required float error;
|
|
|
|