Results 1 to 2 of 2
Thread: java static help
- 02-09-2011, 01:55 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
java static help
so im making this game where i have a method call another method in another class but im getting a
"Cannot make a static reference to the non-static method First() from the type Classtwo" error
now i looked it up but it was confusing on how to fix it as i am vary new at java
ill post the relevant code(sorry about the random lines in there i have been trying to figure it out myself for a long time :p :
Java Code:import java.applet.Applet; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.geom.AffineTransform; public class NearMiss extends Applet implements Runnable, KeyListener { private Player player; private Player TurnClockwise; public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); keys[key]=true; System.out.println("User pressed key " + e.getKeyCode() +keys[key]+ Player.Dplayer_info[1]); } public void keyReleased(KeyEvent e) { int key = e.getKeyCode(); keys[key]=false; System.out.println("User released key " +keys[key]+ e.getKeyCode()); } public void run () { Thread.currentThread().setPriority(Thread.MIN_PRIORITY); while(true) { if (keys[39] = true ) { Player.TurnClockwise(); } repaint(); try { Thread.sleep (10); } catch (InterruptedException ex) { // do nothing } Thread.currentThread().setPriority(Thread.MAX_PRIORITY); } ///Class2 public class Player { public double Dplayer_info[]=new double[10] ; public Player() { Dplayer_info[1] = 1; Dplayer_info[2] = 10; Dplayer_info[3] = 0; } public void TurnClockwise() { Dplayer_info[1] = Dplayer_info[1] + Dplayer_info[2]; System.out.println(Dplayer_info[1]); } }
- 02-09-2011, 01:58 AM #2
Similar Threads
-
Can't make static reference to non-static method -> huh?! Simple car prgm
By enerj in forum New To JavaReplies: 7Last Post: 09-24-2010, 05:09 AM -
non-static method getType cannot be referenced from a static contex
By Dekkon0 in forum New To JavaReplies: 4Last Post: 05-12-2010, 11:05 AM -
Java class HashIt with a static recursive method and a static iterative method
By kezkez in forum New To JavaReplies: 3Last Post: 02-09-2010, 05:22 AM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks