Results 1 to 3 of 3
  1. #1
    bri1547 is offline Member
    Join Date
    Jul 2008
    Posts
    24
    Rep Power
    0

    Default Help with Compile time errors

    I am having trouble resolving some compile time errors that I am getting. Can anyone help? Below is the code and the error messages:

    Java Code:
    import java.io.PrintWriter;
    
    import java.util.Scanner;
    
    import java.util.Vector;
    
    
    
    
    public class InventoryList extends Vector<Inventory>
    
    {
    	
       public enum EPosition
    	
       {
    		FIRST,
    		PREVIOUS,
    		NEXT,
    		LAST
    	};
    
    
          private int current = -1;
    
    	
    	
       public Inventory getCurrent()
    	
       {
    		
          if ( current != -1 )
    			
             return elementAt(current);
    		
          else
    		
             return null;
    		
    	
       }
       
       public boolean isLast()
    	
       {
    		
          if ( current == size() - 1 )
    			
             return true;
    		
          else
    			
             return false;
    
        }	
    	
    	
    
       public boolean add( Inventory item  )
    	
       {
    		
          boolean result = super.add( item  );
    		
          if ( result == true )
    
             current = size() - 1;
    		
             return result;
    	
       }
    	
    	
    
       public void removeCurrent()
    	
       {
    		
          if ( current >= 0 )
    			
             remove( current );
    
    		
          if ( current >= size() )
    			 
             current = size() - 1;
    	
       }
       
    
       public void setCurrent( EPosition pos )
    	
       {
    		
          if ( isEmpty() )
    		
          { 
             current = -1;
    
          }        		
    		
          else
          {
    		
    
    	 switch (pos)
    			
             {
    				
                case FIRST:
    					
                current = 0;
    					
                break;
    	
    			
                case PREVIOUS:
    					
                current += size();
    					
                -- current;
    					
                break;
    
    			
                case NEXT:
    					
                ++ current;
    					
                break;
    				
    
                case LAST:
    					
                current = size() - 1;
    					
                break;
    			
             }
    			
          current %= size();
    
          }		
       }
    		
    	
    
       public void replaceCurrent( Inventoryitem )
    	
       {
    		
          set( current, item  );
    	
       }
    	
    	
    
       public Inventory[] asArray()
    	
       {
    		
          Inventory[] items = new Inventory[size()];
    		
          return toArray(items);
    	
       }
    	
    	
    
       public void write( PrintWriter pw )
    	
       {
    		
          pw.println( Inventory.getRestockingFee() );
    		
          pw.println();
    		
    		
          for( Inventory item : this )
    		
          {
    			
             item.write( pw );
    			
             pw.println();
    		
          }
    
       }
    
    	
    
       public void readFrom( Scanner sc )
    	
       {
    		
          clear();
    		
          Inventory.setRestockingFee( sc.nextDouble() );
    		
          while( sc.hasNextInt() )
    		
          {
    			
             int itemNumber = sc.nextInt();
    			
             sc.nextLine();
    			
             String itemName = sc.nextLine();
    			
             String sellingVenue = sc.nextLine();
    			
             int unitsInStock = sc.nextInt();
    			
             double unitPrice = sc.nextDouble();
    			
    			
             Inventory item = new Inventory(itemNumber, itemName, sellingVenue, unitsInStock, unitPrice);
    			
             add(item);
    		
          }
    		
    	
       }
    
    }
    .\InventoryList.java:154: <identifier> expected
    public void replaceCurrent( Inventoryitem )
    ^
    .\InventoryList.java:154: cannot find symbol
    symbol : class Inventoryitem
    location: class InventoryList
    public void replaceCurrent( Inventoryitem )
    ^
    .\InventoryList.java:159: cannot find symbol
    symbol : method set(int,java.lang.String)
    location: class InventoryList
    set( current, item );
    ^

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Is line 154 inside your class? Hard to tell from the long listing you've posted.
    Where is the set() method you are using on line 159 defined?
    Is it in scope at that line?

    public void replaceCurrent( Inventoryitem )
    You need to add a variable name after the type. It looks like you meant to enter item.

    Can you remove the extra blank lines when you post code. It makes the post TOO long.
    Last edited by Norm; 08-24-2008 at 11:12 PM.

  3. #3
    bri1547 is offline Member
    Join Date
    Jul 2008
    Posts
    24
    Rep Power
    0

    Default

    Norm,

    Sorry for not taking out the extra spaces. As I was reading your post I noticed that I did not have a space between inventory and item in the method name. I put the space in and everything worked great! Thanks for your help!

Similar Threads

  1. makeButton errors
    By ljk8950 in forum AWT / Swing
    Replies: 12
    Last Post: 08-10-2008, 01:10 AM
  2. help with these errors
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 04:55 PM
  3. Errors I don't understand
    By MattyB in forum New To Java
    Replies: 4
    Last Post: 04-01-2008, 11:55 PM
  4. I have 3 errors after compiling
    By coco in forum JDBC
    Replies: 2
    Last Post: 10-18-2007, 09:32 AM
  5. Errors in constructor
    By ai_2007 in forum Advanced Java
    Replies: 0
    Last Post: 07-01-2007, 05:35 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
  •