Page 1 of 2 12 LastLast
Results 1 to 20 of 26
  1. #1
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Java Code:
    while ((mydata.hasNextInt()) != null ) {
    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()) {

    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);
    ^
    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?


    line 75 vectorlength=tempvector.getLength();

    VectorAssignment.java:75: cannot find symbol
    symbol : method getLength()
    location: class java.util.Vector
    vectorlength=tempvector.getLength();
    ^
    3 errors
    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.

    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 04:08 PM.

  3. #3
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    thank you that solve first error.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  5. #5
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    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

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  7. #7
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    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

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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!

  9. #9
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    Java 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();
      
       }        
                     
              
        
    }
    the error
    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 you
    Last edited by Wishes; 11-25-2010 at 05:14 PM.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Please edit your post above and change the [quot&#101;] and [/quot&#101;] tags to [cod&#101;] and [cod&#101;] tags. Thank you.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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]

  12. #12
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    hey
    I cant put specific number because that is depend on input file .
    maybe i will change it to linked list

    thank you

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Wishes View Post
    hey
    I cant put specific number because that is depend on input file .
    maybe i will change it to linked list

    thank you
    Yes, or an ArrayList. If you use one of these, and you want it to hold integer-type information, then yes you were correct in that you'll need to use the object wrapper for int, Integer.

  14. #14
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    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

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Wishes View Post
    How I can In initialize ArrayList
    I still have the same error with (ArrayList <BodorVector> vectors)


    Java Code:
    ArrayList<BodorVector> vectors [color="red"]= new ArrayList<BodorVector>();[/color]

  16. #16
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    Thank you very much , I will fix my code and try it

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    good luck!

  18. #18
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    hey

    Finally my program compiler sucesful , but I have this message when I want run my code
    Java 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)
    This my code
    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
       }        
                     
              
        
    }

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  20. #20
    Wishes is offline Member
    Join Date
    Nov 2010
    Posts
    20
    Rep Power
    0

    Default

    HEY
    GOOD morning
    its work now but its give me the result wromg i am trying fix it .
    about my code
    I CHANGE THE BUFFER READER TO SCANNER
    I REPLACE SWITCH WITH IF ,ELSE STATEMENT
    I USED TRY,CATCH BLOCK

    Thank you

Page 1 of 2 12 LastLast

Similar Threads

  1. Java compile error
    By socboy6579 in forum New To Java
    Replies: 7
    Last Post: 10-14-2010, 07:48 PM
  2. Compile Error
    By gcorreageek in forum Advanced Java
    Replies: 2
    Last Post: 09-08-2010, 06:23 AM
  3. compile error
    By angryredantz in forum New To Java
    Replies: 1
    Last Post: 01-23-2009, 11:44 PM
  4. Compile Error - Please Help!!
    By AJ2009 in forum New To Java
    Replies: 10
    Last Post: 01-04-2009, 04:59 PM
  5. compile error
    By dirtycash in forum New To Java
    Replies: 6
    Last Post: 12-12-2007, 07:00 PM

Posting Permissions

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