Results 1 to 7 of 7
  1. #1
    likeafire is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default Need help please

    I am testing a queue and im trying to insert a number onto the queue but i keep getting an error message saying - <identifier> expected. Anyone know how i can fix this so that i can output the number i want to add onto my queue. Any help will be much appreciated. Here is the code:

    public class NewArray
    {
    ArrayPriorityQueue myarray = new ArrayPriorityQueue(5);

    public void myprogobj();

    System.out.println(myarray.enqueue(4)); (<identifier> expected)
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by likeafire View Post
    public void myprogobj();
    What is that line doing there?

    kind regards,

    Jos

  3. #3
    likeafire is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    What is that line doing there?

    kind regards,

    Jos
    Its just something im gonna use for later but even if i delete that line the error message still appears.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by likeafire View Post
    Its just something im gonna use for later but even if i delete that line the error message still appears.
    Remove that line and take the next line (written in bold in your OP) to the body of a method; what you wrote isn't syntactically correct Java.

    kind regards,

    Jos

  5. #5
    likeafire is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Remove that line and take the next line (written in bold in your OP) to the body of a method; what you wrote isn't syntactically correct Java.

    kind regards,

    Jos
    Ok im a beginner in java so could you possibly tell me what you by 'to the body of a method'. Thanks.

  6. #6
    likeafire is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    Ok this is what i have now:

    public class NewArray
    {
    public void myprogobj()
    {

    ArrayPriorityQueue myarray = new ArrayPriorityQueue(5);

    myarray.enQueue(4);
    myarray.enQueue(3);

    }
    public static void main (String args[]){

    System.out.println(myarray);
    }
    }



    But the problem is i cant get it to output anything and an error is produced saying that it cannot find symbol - variable myarray where i have put System.out.prinln(myarray);

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

    Default

    Its a scope problem. There is no variable myarray that is in scope for the main() method.
    myarray is a local variable in the myprogobj method.
    You need to move its definition outside of any methods so all methods can see it.

    Your next problem will be trying to access a non-static variable from a static context.

Posting Permissions

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