5 Replies - 309 Views - Last Post: 09 November 2012 - 01:03 AM Rate Topic: -----

#1 toad87  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 188
  • Joined: 21-May 12

instanceOf error

Posted 08 November 2012 - 11:56 PM

I'm having trouble using instanceOf in my if statements. What I have here is an ArrayList of GamePiece subclass items: Enemy and Npc. I want to display all Enemy's in the list and all Npc's in the list in two seperate methods.

public void displayNpc()
    {
        for(GamePiece piece : gamePieces){
            if(piece instanceOf Npc){
                System.out.println(piece);
                
            }
        }

    }



and the same method for Enemy.

But my compiler keeps saying I'm miss a ')'. I don't get it....I've looked everywhere on the internet and all the examples are shown like my code above.

Any help is greatly appreciated. Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: instanceOf error

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: instanceOf error

Posted 09 November 2012 - 12:14 AM

Can you please post the exact error message that you are getting along with the rest of your code.

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#3 MattDelly  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 43
  • Joined: 08-November 12

Re: instanceOf error

Posted 09 November 2012 - 12:21 AM

What you've provided seems to be right. Maybe it's a problem elsewhere? As Raghav said it would be helpful to see the whole thing.
Was This Post Helpful? 0
  • +
  • -

#4 farrell2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,576
  • Joined: 29-July 11

Re: instanceOf error

Posted 09 November 2012 - 12:34 AM

It's instanceof, not instanceOf. Understandable mistake :-P

This post has been edited by farrell2k: 09 November 2012 - 12:35 AM

Was This Post Helpful? 1
  • +
  • -

#5 MattDelly  Icon User is offline

  • New D.I.C Head

Reputation: 9
  • View blog
  • Posts: 43
  • Joined: 08-November 12

Re: instanceOf error

Posted 09 November 2012 - 12:37 AM

View Postfarrell2k, on 09 November 2012 - 12:34 AM, said:

It's instanceof, not instanceOf. Understandable mistake :-P

Didn't catch that haha Good call
Was This Post Helpful? 0
  • +
  • -

#6 toad87  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 188
  • Joined: 21-May 12

Re: instanceOf error

Posted 09 November 2012 - 01:03 AM

Oh my lordy lord....

Thanks so much. I owe you a big fat kiss :).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1