The Artima Developer Community
Sponsored Link •

Java Answers Forum
cannot be referenced from a static context

1 reply on 1 page. Most recent reply: Apr 12, 2007 1:48 AM by Rajeev Mutalik

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Ross Davison

Posts: 1
Nickname: javame
Registered: Apr, 2007

cannot be referenced from a static context Posted: Apr 11, 2007 10:54 AM
Reply to this message Reply
Advertisement
im trying to link my user interface to the Game class to jump,
i get the error - non static method jump() cannot be referenced from a static context

private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
// code
Game.jump();
}

any ideas? thanks


Rajeev Mutalik

Posts: 57
Nickname: rajmutalik
Registered: Sep, 2002

Re: cannot be referenced from a static context Posted: Apr 12, 2007 1:48 AM
Reply to this message Reply
Hi,

Do not call jump method using Game.jump. Because its not static. So there are two ways now:
1. Declare jump method as static
private static void jump() {...}

2. Or else create an object of Game and then call jump
private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println( "\njButton1_actionPerformed(ActionEvent e) called.");
// code
Game game = new Game();
game.jump();
}

Regards,
Rajeev



> im trying to link my user interface to the Game class to
> jump,
> i get the error - non static method jump() cannot be
> referenced from a static context
>
> private void jButton1_actionPerformed(ActionEvent e)
> {
> System.out.println("\njButton1_actionPerformed(ActionEve
> nt e) called.");
> // code
> Game.jump();
> }
>
> any ideas? thanks

Flat View: This topic has 1 reply on 1 page
Topic: cannot be referenced from a static context Previous Topic   Next Topic Topic: what won't my applet run

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use