Results 1 to 20 of 26
- 11-25-2010, 02:53 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
I have Compile error but I couldn't fix it
hey
each time I comile my code I have this error but i dont know what is wrong
line 37 : while ((mydata.hasNextInt()) ! = null ) {
VectorAssignment.java:37: incomparable types: boolean and <nulltype>
while ((mydata.hasNextInt()) != null ) {
^
line 56 :Vector tempvector= new Vector(startpoint,endpoint);
VectorAssignment.java:56: cannot find symbol
symbol : constructor Vector(Point,Point)
location: class java.util.Vector
tempvector= new Vector(startpoint,endpoint);
^
line 75 vectorlength=tempvector.getLength();
VectorAssignment.java:75: cannot find symbol
symbol : method getLength()
location: class java.util.Vector
vectorlength=tempvector.getLength();
^
3 errors
I dont KNOW WHAT WRONG I DID
THANK YOU
Wishes
-
mydata is a Scanner object I assume? If so, hasNextInt() returns a boolean -- true if there is another int token available to be scanned and false if not, and it doesn't make sense to see if a boolean is null since it's a primitive. Better is to simply get rid of the != null part:Java Code:while ((mydata.hasNextInt()) != null ) {
Java Code:while (mydata.hasNextInt()) {The compiler is telling you exactly what's wrong -- simply that Vector has no constructor that takes two points as parameters. And in fact the compiler is correct, and the API will tell you what constructors are available for Vector. What are you trying to do here since I can't tell based on this code snippet?
ine 56 :Vector tempvector= new Vector(startpoint,endpoint);
VectorAssignment.java:56: cannot find symbol
symbol : constructor Vector(Point,Point)
location: class java.util.Vector
tempvector= new Vector(startpoint,endpoint);
^
Again, the compiler is telling you exactly what's wrong -- there is no getLength() method for Vector. Rather the API will show you that there's a size() method.line 75 vectorlength=tempvector.getLength();
VectorAssignment.java:75: cannot find symbol
symbol : method getLength()
location: class java.util.Vector
vectorlength=tempvector.getLength();
^
3 errors
Two suggestions:
1) believe what the compiler is telling you and try to understand the messages it gives you. They're not too cryptic here.
2) Get to know and use the Java API.
Much luck!
edit: not length() but size()!Last edited by Fubarable; 11-25-2010 at 03:08 PM.
- 11-25-2010, 03:06 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
thank you that solve first error.
-
- 11-25-2010, 03:15 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
thank you again
but this is my class vector
mport java.math.*;
class Vector {
private Point start;
private Point finish;
private double length ;
public Vector (Point x, Point y ){
start = x;
finish = y ;
}
private void calculatelength (){
int dimes = start.getDim();
integer[] st= start.getCords();
integer[] fini=finish.getCords();
int result =0;
for (int i=0 ; i< dim ;i++)
{int dif=0;
dif=st[i]-finis[i];
dif = dif * dif ;
result= result + dif;
}
length = Math.sqrt(result)
public double getLength ()
{return length ;
}
}
it has constructor with two point and has method getlength.
thank you
Wishes
-
Aha!!! You have your own class named Vector, and this is confusing us (and the compiler)!
The compiler is looking for methods and constructors in the java.util.Vector class, not your class. I strongly urge you to rename your class from Vector to something that is not already a class name in the standard Java library, such as MyVector or some such.
- 11-25-2010, 03:47 PM #7
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
thank you very much you save my life i was trying all last week
I change myclass name now but I have 8 error for all my variable :
might not have been initialized
is any library in java to expline the error meaning .
thank you
-
It usually means that you need to give those variables some initial values. So perhaps when you declare the variables, initialize them. If still problems, post your latest code (with code tags please) and the actual error messages.
Luck!
- 11-25-2010, 04:02 PM #9
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
the errorJava Code:import java.io.*; import java.util.*; class VectorAssignment { public static void main(String[] args) throws IOException { ArrayList <BodorVector> vectors; int vectorsNumber=0,vectordimension=0; Point startpoint , endpoint; Integer[] vectorcordinate; Scanner mydata = null; double vectorlength; BodorVector TempVector; //open+read+close // create write + close // Open the file that is the first // Get the object of DataInputStream mydata= new Scanner(new BufferedReader(new FileReader("input.txt"))); /* FileReader data = new FileReader("Test.txt"); Scanner mydata = new Scanner(data); */ // start read input file and fill the vectors list while (mydata.hasNextInt()) { for (int i=0 ;i<3 ;i++){ switch (i) { case 1: vectordimension=mydata.nextInt() // first line is dim ; break; case 2:for(int s=0; s< vectordimension;s++) // second line is first points vectorcordinate[s]=mydata.nextInt(); startpoint= new Point(vectordimension,vectorcordinate); // third line is ; break; case 3: for(int f=0; f< vectordimension;f++) vectorcordinate[f]=mydata.nextInt(); endpoint= new Point(vectordimension,vectorcordinate); break; }//switch }//for TempVector=new BodorVector(startpoint,endpoint); vectors.add(TempVector); // constructor vector with start and end point vectorsNumber++; // count vectors } // while mydata.close();// close the file after finish reading // reading the file is finish // write the vector in file FileWriter output = new FileWriter("output.txt"); BufferedWriter outputdata = new BufferedWriter(output); outputdata.write("Hello YOU have "+ vectorsNumber); for(int c=0;c<vectorsNumber;c++) { TempVector=vectors.get(c); vectorlength=TempVector.getLength(); outputdata.write("The length of vector number **" + vectorsNumber + " equal" + vectorlength); } // for System.out.println("Thank you , The data has been written"); outputdata.flush(); outputdata.close(); } }
Java Code:C:\>javac VectorAssignment.java VectorAssignment.java:45: variable vectorcordinate might not have been initializ ed vectorcordinate[s]=mydata.nextInt(); ^ VectorAssignment.java:46: variable vectorcordinate might not have been initializ ed startpoint= new P oint(vectordimension,vectorcordinate); ^ VectorAssignment.java:50: variable vectorcordinate might not have been initializ ed vectorcordinate[f]=mydata.nextInt(); ^ VectorAssignment.java:51: variable vectorcordinate might not have been initializ ed endpoint = new Point(vectordimension,vectorcordinate); ^ VectorAssignment.java:56: variable startpoint might not have been initialized TempVector=new BodorVector(startpoint,endpoint); ^ VectorAssignment.java:56: variable endpoint might not have been initialized TempVector=new BodorVector(startpoint,endpoint); ^ VectorAssignment.java:57: variable vectors might not have been initialized vectors.add(TempVector); ^ VectorAssignment.java:75: variable vectors might not have been initialized TempVector=vectors.get(c); ^ 8 errors
thank youLast edited by Wishes; 11-25-2010 at 04:14 PM.
-
Please edit your post above and change the [quote] and [/quote] tags to [code] and [code] tags. Thank you.
-
Your vectorcordinate variable, which should probably be spelled vectorCoordinate, should also probably be an int[] array not an Integer[] array, and you need to initialize it with a size -- how big it is going to be:
Java Code:int[] vectorCoordinate [color="red"][b]= new int[10]; // or however big it is supposed to be[/b][/color]
- 11-25-2010, 04:33 PM #12
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
hey
I cant put specific number because that is depend on input file .
maybe i will change it to linked list
thank you
-
- 11-25-2010, 05:00 PM #14
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
Hey
How I can In initialize ArrayList
I still have the same error with (ArrayList <BodorVector> vectors)
Java Code:C:\>javac VectorAssignment.java VectorAssignment.java:59: variable vectors might not have been initialized vectors.add(TempVector); ^ VectorAssignment.java:77: variable vectors might not have been initialized TempVector=vectors.get(c); ^ 2 errors
-
- 11-25-2010, 05:10 PM #16
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
Thank you very much , I will fix my code and try it
-
good luck!
- 11-25-2010, 10:16 PM #18
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
hey
Finally my program compiler sucesful , but I have this message when I want run my code
This my codeJava Code:C:\>java VectorAssignment Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1461) at java.util.Scanner.nextInt(Scanner.java:2091) at java.util.Scanner.nextInt(Scanner.java:2050) at VectorAssignment.main(VectorAssignment.java:47)
Java Code:class VectorAssignment { public static void main(String[] args) { ArrayList <BodorVector> vectors=new ArrayList<BodorVector>(); int vectorsNumber=0,vectordimension=0; Integer[] vectorcordinate=new Integer[10]; Point startpoint=new Point(vectordimension,vectorcordinate); Point endpoint =new Point(vectordimension,vectorcordinate); Scanner mydata = null; double vectorlength; BodorVector TempVector=new BodorVector(startpoint,endpoint); //open+read+close // create write + close // Open the file that is the first // Get the object of DataInputStream try{ mydata= new Scanner(new BufferedReader(new FileReader("input.txt"))); /* FileReader data = new FileReader("Test.txt"); Scanner mydata = new Scanner(data); */ // start read input file and fill the vectors list while (mydata.hasNextInt()) { for (int i=0 ;i<3 ;i++){ switch (i) { case 1: vectordimension=mydata.nextInt() // first line is dim ; break; case 2:for(int s=0; s< vectordimension;s++) // second line is first points vectorcordinate[s]=mydata.nextInt(); startpoint= new Point(vectordimension,vectorcordinate); // third line is ; break; case 3: for(int f=0; f< vectordimension;f++) vectorcordinate[f]=mydata.nextInt(); endpoint= new Point(vectordimension,vectorcordinate); break; }//switch }//for TempVector=new BodorVector(startpoint,endpoint); vectors.add(TempVector); // constructor vector with start and end point vectorsNumber++; // count vectors } // while mydata.close();// close the file after finish reading }//try // reading the file is finish catch (FileNotFoundException e) {System.out.println("The file dosen't exist."); System.exit(0); }//catch 1 catch (IOException e) {System.out.println("I/O Error "); System.exit(0); }//catch 2 // write the vector in file try { FileWriter output = new FileWriter("output.txt"); BufferedWriter outputdata = new BufferedWriter(output); outputdata.write("Hello YOU have "+ vectorsNumber); for(int c=0;c<vectorsNumber;c++) { TempVector=vectors.get(c); vectorlength=TempVector.getLength(); outputdata.write("The length of vector number **" + vectorsNumber + " equal" + vectorlength); } // for System.out.println("Thank you , The data has been written"); outputdata.flush(); outputdata.close();}//try2 catch (IOException e) {System.out.println("I/O Error "); System.exit(0); }//catch 3 } }
-
You're trying to read in ints with the myData Scanner objects when there simply are no ints to read. You'd best put in some debug (println) statements to find out what is actually there when you're trying to read ints. Also, you seem to be attempting to read in multiple ints when you've checked hasNextInt only once. In general you should only read in one int if you call hasNextInt once. If you need to read in more ints, you need to call hasNextInt again before reading.
- 11-26-2010, 08:44 AM #20
Member
- Join Date
- Nov 2010
- Posts
- 20
- Rep Power
- 0
Similar Threads
-
Java compile error
By socboy6579 in forum New To JavaReplies: 7Last Post: 10-14-2010, 06:48 PM -
Compile Error
By gcorreageek in forum Advanced JavaReplies: 2Last Post: 09-08-2010, 05:23 AM -
compile error
By angryredantz in forum New To JavaReplies: 1Last Post: 01-23-2009, 10:44 PM -
Compile Error - Please Help!!
By AJ2009 in forum New To JavaReplies: 10Last Post: 01-04-2009, 03:59 PM -
compile error
By dirtycash in forum New To JavaReplies: 6Last Post: 12-12-2007, 06:00 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks