non-static method cannot be referenced from a static context
Hi im a newbie at this ^^;
I get the error message "non-static method cannot be referenced from a static context" when i try to compile my Asteroids class. Im trying to access an arraylist from my spaceRock class.
package Asteroids;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.Timer;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
importstatic java.lang.Character.*;
import java.awt.image.BufferedImage;
importstatic java.lang.System.*;
import Asteroids.Ship;
publicclass Asteroidsextends JFrameimplements KeyListener
{
private Timer timer;
privatefinalstaticint SLEEP = 50;
privateint xHelm = 300;
privateint yHelm = 100;
private Ship Enterprise =new Ship();
private spaceRock Rock =new spaceRock();
private spaceRock s =new spaceRock();
public Asteroids()
{
super("Asteroids :D");
setSize( 650, 550 );
setBackground(Color.black);
this.addKeyListener(this);
ActionListener paintCaller =new ActionListener(){
publicvoid actionPerformed(ActionEvent event)
{
repaint();
xHelm--;
yHelm++;
}
};
timer =new Timer(SLEEP, paintCaller);
timer.start();
setVisible(true);
}
publicvoid paint( Graphics window )
{
Graphics2D twoDGraph = (Graphics2D)window;
int width = this.getWidth();
int height = this.getHeight();
BufferedImage back = (BufferedImage)(this.createImage(width,height));
Graphics graphToBack = back.createGraphics();
Enterprise.launchShip(graphToBack,xHelm,yHelm);
for(int i = 0; i<spaceRock.spawns.size(); i++)//Gives me errors
{
spaceRock r = spaceRock.spawns.get(i);//Gives me errors
r.releaseAsteroid(graphToBack,yHelm+50,xHelm+50);
}
twoDGraph.drawImage(back, null, 0, 0);
}
publicvoid keyTyped(KeyEvent e)
{
if (e.getKeyChar() =='b' || e.getKeyChar() =='B')
{
Enterprise.damageShields();
}
}
publicvoid keyPressed(KeyEvent e)
{
}
publicvoid keyReleased(KeyEvent e)
{
}
publicstaticvoid main( String args[] )
{
Asteroids Game =new Asteroids();
}
}
// spaceRock Class
package Asteroids;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.Image;
import javax.swing.JFrame;
import java.util.ArrayList;
publicclass spaceRockextends JFrame
{
privateint width;
privateint height;
private Image asteroid;
ArrayList><spaceRock> spawns =new ArrayList<spaceRock>();
public spaceRock()
{
width=50;
height=50;
asteroid=null;
}
publicvoid releaseAsteroid(Graphics window,int x,int y)
{
asteroid = Toolkit.getDefaultToolkit().getImage("astero6b.png");
window.drawImage(asteroid,x,y,width,height,this);
}
}
I comment-flagged the lines that give me errors.
Thankyou for your time ^_^

