Results 1 to 2 of 2
  1. #1
    omer.tariq1 is offline Member
    Join Date
    Oct 2013
    Rep Power

    Default static member reference error

    in this function when i try to close my scanner it gives the error"cannot make a static reference to a non static method close()"
    what do i do? i could choose to not close the scanner but it results in a resource leak warning
    node create_left(node head,int serial){
    node temp=new node();*2;
    Scanner a=new Scanner(;
    return head;

  2. #2
    Kagiso is offline Member
    Join Date
    Nov 2012
    Johannesburg, South Africa
    Rep Power

    Default Re: static member reference error

    what does this method do?

    If the error message says
    " ... cannot be referenced from a static context"
    it means that the method you are calling is an instance method... you can't call it in main or in any other static method

    you'd have to create an instance of the class that defines such method the call the method using a reference variable... like you've done when you said a.nextInt()

    try saying a.close() instead of Scanner.close()

Similar Threads

  1. Replies: 5
    Last Post: 03-31-2013, 03:30 AM
  2. Cannot make a static reference to the non-static method
    By Reskaillev in forum New To Java
    Replies: 4
    Last Post: 08-02-2011, 12:42 AM
  3. Replies: 10
    Last Post: 11-14-2010, 07:06 AM
  4. Replies: 7
    Last Post: 09-24-2010, 05:09 AM
  5. Replies: 3
    Last Post: 03-20-2009, 12:35 AM

Tags for this Thread

Posting Permissions

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