Results 1 to 8 of 8

Thread: SOLVED - Arrays in Java

  1. #1
    Stubzz
    Guest

    Talking SOLVED - Arrays in Java

    I am trying to set up an array that hold objects that i am creating, however their parameters are of different types and i get an 'incompatable types error when i try to compile.
    This is the code that i am using:

    PHP Code:
              private Shape[] shape = new Shape[6];
        
    int [] object= new Shape [6];
        
    shape[0] = new Circle(404030Color.red);
        
    shape[1] = new House(808030Color.yellow);
        
    shape[2] = new Square(12012030Color.blue);
        
    shape[3] = new Diamond(16016030Color.green);
        
    shape[4] = new Face(20020030Color.pink);
        
    shape[5] = new Face(24024030Color.black); 
    Object has the following parameter types: Object(int x, int y, int s, string)

    I'm new to java so its probbly a silly mistake. Can someone tell me what I'm doing wrong?

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    What classes are you using? I have not yet come across any classes called Objects. If you have a class myObject (I am not using the name Object, as it's actually a Java class, I think), and want to have an array of objects of the myObject class, your code would be:

    Code:
    private myObject[] objects = new myObject[6];
        objects[0] = new myObject(40, 40, 30, Color.white);
        objects[1] = new myObject(80, 80, 30, Color.yellow);
        objects[2] = new myObject(120, 120, 30, Color.red);
        objects[3] = new myObject(160, 160, 30, Color.black);
        objects[4] = new myObject(200, 200, 30, Color.pink);
        objects[5] = new myObject(240, 240, 30, Color.black);
    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Stubzz
    Guest
    Im using custom sub-classes, i changed the classes to make it more generic. I've changed it now

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Try taking out the second line then:

    Code:
    private Shape[] shape = new Shape[6];
        //int [] object= new Shape [6];
        shape[0] = new Circle(40, 40, 30, Color.red);
        shape[1] = new House(80, 80, 30, Color.yellow);
        shape[2] = new Square(120, 120, 30, Color.blue);
        shape[3] = new Diamond(160, 160, 30, Color.green);
        shape[4] = new Face(200, 200, 30, Color.pink);
        shape[5] = new Face(240, 240, 30, Color.black);
    The commented line would be a mistake, as you are creating an array named object of type integer, but assigning it a reference to a new Shape type array. Also commenting the second line should not affect your desired output, to the best of my knowledge.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5
    Stubzz
    Guest
    Taking out that line doesn't make a difference. The code is currently at the top of the page, but when i move it to the bottom, i get the error: 'can't resolve symbol'

  6. #6
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    are you sure that circle, house, face etc. are subclass of Shape? Ie. in their class they explicitly state extends Shape?

    what symbol does it say that it can't resolve?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  7. #7
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Originally posted by Stubzz
    Taking out that line doesn't make a difference. The code is currently at the top of the page, but when i move it to the bottom, i get the error: 'can't resolve symbol'
    Can you post the entire code?

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  8. #8
    Stubzz
    Guest
    problem solved now thanks for the help guys

Posting Permissions

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



Click Here to Expand Forum to Full Width