Results 1 to 5 of 5
  1. #1
    javanewbie82 is offline Member
    Join Date
    Oct 2016
    Posts
    13
    Rep Power
    0

    Default why isn't my method found?

    I have a class called Alien, a class called AlienPack, and test class. I have an array called pack of type AlienPack. I am trying to call methods from the AlienPack class in my test class and I get "cannot be found" compilation errors. The add method is a void method whereas the damage method is an int. Both public.
    Java Code:
    AlienPack [] pack = new AlienPack [5]
    // .....
    // rest of code works until
    pack.addAlien(aSnake, 1);
    pack.calculateDamage();
    Is it a syntax error?
    Last edited by javanewbie82; 11-26-2016 at 05:38 AM.

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    6

    Default Re: why isn't my method found?

    Is there a method called addAlien() in the Alienpack class and if yes, what parameters does it take?

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: why isn't my method found?

    'pack' is an array of type 'AlientPack' and arrays don't have methods; no matter the methods in the AlienPack class.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    6

    Default Re: why isn't my method found?

    That's true, too. My oversight.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: why isn't my method found?

    It should be called like this:

    Java Code:
    pack[1].addAlien(aSnake, 1);
    pack[1].calculateDamage();
    Or use an int as an index variable into the array.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Error: Main method not found! Please help!
    By xemkruz2012 in forum New To Java
    Replies: 2
    Last Post: 03-11-2013, 11:19 PM
  2. No Main Method Found?
    By connorlm3 in forum New To Java
    Replies: 4
    Last Post: 02-26-2013, 11:35 PM
  3. Main method not found in class
    By kask382 in forum New To Java
    Replies: 8
    Last Post: 02-14-2013, 04:28 PM
  4. Method not found
    By fleg in forum New To Java
    Replies: 8
    Last Post: 10-12-2010, 05:02 PM
  5. JButtonGroup; add() method not found?
    By Moddy in forum AWT / Swing
    Replies: 3
    Last Post: 10-15-2008, 11:08 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
  •