Results 1 to 2 of 2
  1. #1
    Lingerz is offline Member
    Join Date
    Sep 2009
    Rep Power

    Default Non-static method error

    Hello there.

    When I compile the below piece of code, whether the method is static or not, I get "non-static method cannot be referenced from a static context".

    Java Code:
    		public static void createSprite(int spriteID, int x, int y) {
    			BufferedImage img = null;
    		try {
    			    img = File("Sprites/" + spriteID + ".png"));
    				Graphics.drawImage(img, x, y, null);
    		catch (IOException e) {

    The error:

    Java Code: non-static method drawImage(java.awt.Image,int,int,java.awt.ima
    ge.ImageObserver) cannot be referenced from a static context
                                    Graphics.drawImage(img, x, y, null);

    If someone could point out to me what's wrong, or give me a hint on why it does that, I'd be very grateful.

    Thanks in advance.

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    The method you are trying to call is not static but you are calling it using ClassName.methodName, Graphics.drawImage. That is not allowed. Better read the Java basics on how to call methods via references to instances before you try to do any graphics in Java.

Similar Threads

  1. Public static method error
    By leapinlizard in forum New To Java
    Replies: 5
    Last Post: 04-29-2009, 11:10 PM
  2. Replies: 3
    Last Post: 04-11-2009, 09:14 PM
  3. Replies: 1
    Last Post: 02-10-2009, 10:03 AM
  4. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 08:51 AM
  5. Replies: 1
    Last Post: 08-07-2007, 05:05 AM

Posting Permissions

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