Results 1 to 3 of 3
  1. #1
    boy22 is offline Member
    Join Date
    Jul 2007
    Posts
    36
    Rep Power
    0

    Default Error during compiling

    When I compile it returns to me the error:
    Java Code:
    Cars.java:12: Object() in java.lang.Object cannot be applied to (java.lang.String)
    	super(str);
            ^
    1 error
    this is my code:
    Java Code:
      
    public class Cars{
    
        private int free;
    
        public Cars() {
    	
        }
    
        public Cars(String str) {
    
    	super(str);
    	
        }
    
      
    
    }
    any ideas?

  2. #2
    shanePreater is offline Member
    Join Date
    Jul 2007
    Location
    England, Bath
    Posts
    47
    Rep Power
    0

    Default

    You are trying to call the constructor of object with a String.
    The Object class only has a single empty constructor so you can only use
    Java Code:
    public Cars(String str) {
      super();
    }
    If you want to keep the value of str you will need to store it in a member variable which you define in the Cars class.

    Hope that sorts you out. :)

  3. #3
    yiweiang is offline Member
    Join Date
    Aug 2007
    Posts
    15
    Rep Power
    0

    Default

    Hi there,

    If i'm not mistaken, what your code does is that it parses the variable str of type String to this class's superclass' constructor. However, you didn't really define your own superclass? Thus, you are using java's object class, which does not have a constructor that accepts a string value. Try defining your own superclass?

    Yi Wei.

Similar Threads

  1. compiling trouble
    By capacitator in forum CLDC and MIDP
    Replies: 4
    Last Post: 06-10-2008, 10:12 PM
  2. Compiling error
    By lawksalih in forum New To Java
    Replies: 6
    Last Post: 01-29-2008, 07:26 PM
  3. I have 3 errors after compiling
    By coco in forum JDBC
    Replies: 2
    Last Post: 10-18-2007, 09:32 AM
  4. problems when compiling
    By valery in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 07:35 PM
  5. Error while compiling
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2007, 11:37 AM

Posting Permissions

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