Getting java.io.IOException: closed whenever I close my program - java

Every time I Run my program it runs fine. But when I close it after running the program for a few seconds, then I get the java.io.IOException: closed error. I've tried looking around and couldn't find a solution. The only fix I could find was just not using the e.printstacktrace in the try-catch block, but that obviously doesn't fix the issue. Here is the Code:
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main extends Canvas implements Runnable{
private static final long serialVersionUID = -661485289446387445L;
private Thread thread;
public int blackPos;
public int whitePos;
public boolean isWhiteTurn; // In single player this determines board orientation, in multiplayer it doesn't
public boolean running;
public final int HEIGHT = 800;
public final int WIDTH = 1200;
//public File[] imgSrc = {new File("/images/urBoard.png"), new File("/rsc/urBackground.jpg")};
public BufferedImage[] img = new BufferedImage[2];
public Board board;
public Main() {
new Window(WIDTH, HEIGHT, this);
board = new Board(this);
}
public void run()
{
requestFocus();
long lastTime = System.nanoTime();
double amountOfTicks = 60.0D;
double ns = 1.0E9D / amountOfTicks;
double delta = 0.0D;
long timer = System.currentTimeMillis();
int frames = 0;
while (this.running)
{
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while (delta >= 1.0D)
{
tick();
delta -= 1.0D;
}
if (this.running) {
render();
}
frames++;
if (System.currentTimeMillis() - timer > 1000L)
{
timer += 1000L;
System.out.println("FPS: " + frames);
frames = frames;
frames = 0;
}
}
}
public synchronized void start() {
thread = new Thread(this);
thread.start();
running=true;
}
public synchronized void stop() {
try
{
this.thread.join();
this.running = false;
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void tick() {
board.tick();
}
public void render() {
BufferStrategy bs = getBufferStrategy();
if(bs == null) {
createBufferStrategy(3);
return;
}
try {
img[0] = ImageIO.read(getClass().getResource("/rsc/urBoard.png"));
img[1] = ImageIO.read(getClass().getResource("/rsc/urBackground.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
Graphics g = bs.getDrawGraphics();
g.drawImage(img[1], 0, 0, WIDTH, HEIGHT, null);
g.setColor(Color.GREEN);
g.drawLine(200, 0, 200, 800);
g.setFont(new Font("times new roman", Font.BOLD, 30));
g.drawString("END PIECES", 10, 30);
board.render(g);
g.dispose();
bs.show();
}
public static void main(String[] args) {
new Main();
}
}
and here is the error that I get whenver I close the GUI after it has ran for a couple seconds:
java.io.IOException: closed
at javax.imageio.stream.ImageInputStreamImpl.checkClosed(ImageInputStreamImpl.java:110)
at javax.imageio.stream.ImageInputStreamImpl.close(ImageInputStreamImpl.java:857)
at javax.imageio.stream.FileCacheImageInputStream.close(FileCacheImageInputStream.java:250)
at javax.imageio.ImageIO.read(ImageIO.java:1451)
at javax.imageio.ImageIO.read(ImageIO.java:1400)
at main.Main.render(Main.java:99)
at main.Main.run(Main.java:54)
at java.lang.Thread.run(Thread.java:745)
I've noticed that if I close the window right after i start the program the error doesn't come. It only comes when I've run the program for about 3-4 seconds, and then I close the window. What would cause this to happen, and what would be the fix?

It looks like your render() method may be running when closing the app. As your resources aren't changing between render() calls, move this block to the start of the Main() constructor so that img[] is set up once, and throws an exception if resources are not found:
try {
img[0] = ImageIO.read(getClass().getResource("/rsc/urBoard.png"));
img[1] = ImageIO.read(getClass().getResource("/rsc/urBackground.jpg"));
} catch (IOException e) {
throw new RuntimeException("Could not find resources");
}
The field running is used in different threads so it should be marked volatile in order that each thread reads consistent values:
public volatile boolean running;

Related

Having trouble animating my player character, and other animated objects

Before I start, here is my UML diagram:
I'm trying to animate my player's character, of a gif but split into 5 separate png files. I'd rather work when the 5 frames directly because it's not a detailed image, just an 8-bit character sprite. Also, don't know how to use many Photo editing software, so I'm using the separate files themselves.
I've tried quite a few examples off Stack Overflow and other tutorials but nothing seems to match what I'm trying to do on the framework I have to build for my game. It's for an end of semester project but I'm planning to build upon in after the due date and keep it open source.
Here is some of my code.
Driver. Loads the game loop and other functions.
package cactus;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class Driver extends Canvas implements Runnable{
private static final long serialVersionUID = 1L;
private Thread t;
private boolean running;
private Controller controller;
public Driver() {
controller = new Controller();
/*--- Add Game Objects ---------------------------------------*/
controller.addObject(new Travis(500, 675, ID.Travis));
/*------------------------------------------------------------*/
}
public synchronized void start() {
t = new Thread(this);
t.start();
running = true;
}
public synchronized void stop() {
try {
t.join();
running = false;
} catch (Exception e) {
e.printStackTrace();
}
}
public void run() {
this.requestFocus();
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int frames = 0;
while(running) {
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while(delta >= 1) {
tick();
delta--;
}
if(running) {
render();
}
frames++;
if(System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println("FPS:" + frames);
frames = 0;
}
}
stop();
}
private void tick() {
controller.tick();
}
private void render() {
BufferStrategy buffer = this.getBufferStrategy();
if (buffer == null) {
this.createBufferStrategy(3);
return;
}
Graphics g = buffer.getDrawGraphics();
g.drawImage(background.getCurrentBG(), 0, 0, Frame.getWidth(), Frame.getHeight(), null);
controller.render(g);
g.dispose();
buffer.show();
}
public static void main(String[] args) {
new Driver();
}
}
Controller. Loops through game objects to execute some of their render functions, which displays what they look like, and their tick functions which controls their locations and some future actions.
package cactus;
import java.awt.Graphics;
import java.util.LinkedList;
public class Controller {
LinkedList<Objects> gameObj = new LinkedList<Objects>();
public void tick() {
for (int i = 0; i < gameObj.size(); i++) {
Objects currentObject = gameObj.get(i);
if (currentObject.getId() == ID.ShootFire && currentObject.getX() > Frame.getWidth() + 30) {
removeObject(currentObject);
System.out.println("Fire Object Removed");
}
currentObject.tick();
}
}
public void render(Graphics g) {
for (int i = 0; i < gameObj.size(); i++) {
Objects currentObject = gameObj.get(i);
currentObject.render(g);
}
}
public void addObject(Objects o) {
this.gameObj.add(o);
}
public void removeObject(Objects o) {
this.gameObj.remove(o);
}
}
Player class. Gets methods from Abstract Objects class
package cactus;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
// import javax.swing.Timer;
public class Travis extends Objects implements ActionListener{
ArrayList<BufferedImage> animation;
// Timer animationTimer;
Graphics g;
// int i = 0;
public Travis(int x, int y, ID id) {
super(x, y, id);
this.animation = createAnimation();
// this.animationTimer = createTimer(animationTimer);
// animationTimer.start();
}
private synchronized ArrayList<BufferedImage> createAnimation() {
animation = new ArrayList<BufferedImage>();
for (int i = 0; i < 6; i++) {
try {
animation.add(ImageIO.read(new File("./src/resources/image/travis/frame_" + i + ".png")));
} catch (IOException e) {e.printStackTrace(); System.exit(0);}
}
return animation;
}
// private synchronized Timer createTimer(Timer animationTimer) {
// animationTimer = new Timer(15, this);
// animationTimer.setDelay(15*1000);
// return animationTimer;
// }
#Override
public void tick() {
x += velocityX;
}
/*
* drawImage(img, posX, posY, observe [null])
*
* (non-Javadoc)
* #see cactus.GameObjects#render(java.awt.Graphics)
*/
#Override
public void render(Graphics g) {
for (int i = 0; i < 6; i++) {
g.drawImage(animation.get(i), x, y, null);
}
if (i == 6)
i = 0;
}
#Override
public void actionPerformed(ActionEvent e) {
}
}
I want each object of the ArrayList (although likely will change it to Map), to play with different delays between frames.
* frame_0: 1s
* frame_1: 2s
* frame_2: 2s
* frame_3: 1s
* frame_4: 2s
* frame_5: 5s
I've tried using Timer and some other things and I'm not able to animate it, it just displays the last frame.
I don't have enough rep to post photographs.
The simplest approach is to yield the rendering thread by sleeping it for a few milliseconds between frames:
private static final long PERIOD = 1000 / FRAMES_PER_SECOND;
...
long now = System.currentTimeMillis();
while(running) {
// Perform frame
...
// Wait for next frame
now += PERIOD;
final long duration = now - System.currentTimeMillis();
if(duration > 0) {
Thread.sleep(duration);
}
}
where FRAMES_PER_SECOND is the desired number of frames-per-second.
You could also add a counter to calculate the frame-rate if required.
There are lots of other (and better) ways of creating a render loop but this should do as a starter.

Java game, colors don't apear

I have this code for a game called Wave, and normally when I run it, it should be a black window with white squares in it. But the window is white, with a very thin black stripe on the left of the window. I can barely see it.
Does anybody have any idea on why would this happen?
package wave.myFirstGame;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.util.Random;
public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 3580879553502102315L;
public static final int WITDH = 640, HEIGHT = WITDH / 12 * 9;
private Thread thread;
private boolean running = false;
private Random r;
public Handler handler;
public Game() {
new Window(WITDH, HEIGHT, "Wave", this);
handler = new Handler();
r = new Random();
for(int i = 0; i < 50; i++){
handler.addObject(new Player(r.nextInt(WIDTH), r.nextInt(HEIGHT), ID.Player));
}
handler.addObject(new Player(200, 200, ID.Player));
}
public synchronized void start() {// initializing the thread
thread = new Thread(this);
thread.start();
running = true;
}
public synchronized void stop() {
try {
thread.join();
running = false;
} catch (Exception e) {
e.printStackTrace();
}
}
// GAME LOOP
public void run() {
long lastTime = System.nanoTime();
double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
long timer = System.currentTimeMillis();
int frames = 0;
while (running) {
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
while (delta >= 1) {
tick();
delta--;
}
if (running)
render();
frames++;
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println("FPS " + frames);
frames = 0;
}
}
stop();
}
private void tick(){
handler.tick();
}
private void render(){
BufferStrategy bs = this.getBufferStrategy();
if(bs == null){
this.createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.setColor(Color.black);
g.fillRect(0, 0, WIDTH, HEIGHT);
handler.render(g);
g.dispose();
bs.show();
}
public static void main(String[] args) {
new Game();
}
}
Have a look into the API of Canvas. There you will find:
Fields inherited from interface java.awt.image.ImageObserver
[...] HEIGHT, [...], WIDTH
So since you extend your class from Canvas class you already have WIDTH and HEIGHT constants and for some reason WIDTH seams to have value 1.
So simply rename your constants and it will display as expected.

BufferStrategy and Graphics g

I have a sprite sheet that I want to use in a src folder within the project. Here is some code I have for a simple game I am making. I get an error when trying to draw anything with the paintbrush or (g). Can you help me figure out what is wrong?
I have a pre-existing background that I want to draw the images over. I deleted the code, the background image isn't what's causing the issues.
package NewCards;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferStrategy;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class Game extends JFrame implements Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private boolean live = false; //running
private boolean dead = false;
//instances of external classes here.
private Thread thread;
/**
* Launch the application.
*/
//initialize here.
public void init() {
}
private synchronized void start() {
if (running)
return;
live = true;
thread = new Thread(this);
thread.start();
}
private synchronized void stop() {
if(!running)
return;
try {
thread.join(); //attempts to join threads, if unsuccessful, throw Exception error.
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.exit(1);
}
public void run() {
init();
long lasttime = System.nanoTime();
final double amountofticks = 60.0;
double ns = 1000000000 / amountofticks;
double delta = 0;
int update = 0;
int frames = 0;
long timer = System.currentTimeMillis();
// TODO Auto-generated method stub
while (running) {
long now = System.nanoTime();
delta += (now - lasttime) / ns;
lasttime = now;
if (delta >= 1) {
tick();
update++;
delta--;
}
render();
frames++;
if(System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println(update + " Frames, FPS: " + frames);
update = 0; // resets fps for updates. If not the beats would just double.
frames = 0; // statement above applies here in terms of FPS
}
}
stop();
}
private void tick(){
}
private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs== null) {
createBufferStrategy(3);
return;
}
Graphics g = bs.getDrawGraphics();
g.fillRect(1, 1, 200, 500);
g.dispose();
bs.show();
}
public static void main(String[] args) {
final Game game = new Game(); //game starter.
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Game frame = new Game();
JLabel backgroundImage = new JLabel();
backgroundImage.setSize(800, 800);
frame.getContentPane().add(backgroundImage);
Image background = new ImageIcon(this.getClass().getResource("/Artificial intelligence.png")).getImage();
backgroundImage.setIcon(new ImageIcon(background));
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
game.start();
}
});
}
/**
* Create the frame.
*/
public Game() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 800, 800);
setTitle("MyEmpire-1.1.1/Windows/Display/Menus/Loop");
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
}
}

Game Applet not running in 2D game (while loop)

I'm trying to set the dimensions for this game i want to create. The error is at while(running); I went over it for an hour but i can't seem to catch the error. I'm using NetbeansIDE also setPreserredSize (new Dimension(WIDTH, HEIGHT)); gives me an error, it is asking to Create a method " setPrefferedSize(java.awt.Dimension)"in.com.francesc.game.Game
private void setPreserredSize(Dimension dimension) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
when i run it i get this error
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of type
at com.francescstudio.game.Game.<init>(Game.java:67)
at com.francescstudio.game.Start.main(Start.java:16)
Java Result: 1
heres all the code
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
/**
*
* #author francesc
*/
public class Game extends JPanel implements KeyListener, Runnable {
public static final long SerialVersionUID = 1L;
public static final int WIDTH = 400;
public static final int HEIGHT = 630;
public static final Font main = new Font("Bebas Nue Regular", Font.PLAIN, 28);
private Thread game;
private boolean running;
private BufferedImage Image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
private long startTime;
private long elapse;
private boolean set;
public Game() {
setFocusable(true);
setPreserredSize (new Dimension(WIDTH, HEIGHT));
addKeyListener(this);
}
private void update() {
}
private void render() {
Graphics2D g = (Graphics2D) Image.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, WIDTH, HEIGHT);
// render board
g.dispose();
Graphics2D g2d = (Graphics2D) getGraphics();
g2d.drawImage(Image, 0, 0, null);
g2d.dispose();
}
#Override
public void run() {
}
int fps = 0, update = 0;
long fpsTimer = System.currentTimeMillis();
double nsPerUpdate = 1000000000.0 / 60;
// last update time in nano seconds
double then = System.nanoTime();
double unprocessed = 0;
while (running){
boolean shouldRender = false;
double now = System.nanoTime();
unprocessed += (now - then) / nsPerUpdate;
then = now;
// update queque
while (unprocessed >= 1) {
update++;
update();
unprocessed--;
shouldRender = true;
}
// render
if (shouldRender) {
fps++;
render();
shouldRender = false;
} else {
try {
Thread.sleep(1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public synchronized start(){
if(running)return;
running = true;
game = new Thread (this, "game");
game.start();
}
public synchronized stop (){
if(!running) return;
running = false;
System.exit(0);
}
#Override
public void keyTyped(KeyEvent e) {
}
#Override
public void keyPressed(KeyEvent e) {
}
#Override
public void keyReleased(KeyEvent e) {
}
}
Your problem is while (running) {} isn't inside of a method, you defined it in the class where it will never get called.
EDIT:
Your code should look something a little more like this
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;
/**
*
* #author francesc
*/
public class Game extends JPanel implements KeyListener, Runnable {
public static final long SerialVersionUID = 1L;
public static final int WIDTH = 400;
public static final int HEIGHT = 630;
public static final Font main = new Font("Bebas Nue Regular", Font.PLAIN, 28);
private Thread game;
private boolean running;
private BufferedImage Image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
private long startTime;
private long elapse;
private boolean set;
public Game() {
setFocusable(true);
setPreferredSize(new Dimension(WIDTH, HEIGHT));
addKeyListener(this);
}
private void update() {}
private void render() {
Graphics2D g = (Graphics2D) Image.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, WIDTH, HEIGHT);
// render board
g.dispose();
Graphics2D g2d = (Graphics2D) getGraphics();
g2d.drawImage(Image, 0, 0, null);
g2d.dispose();
}
#Override
public void run() {
int fps = 0, update = 0;
long fpsTimer = System.currentTimeMillis();
double nsPerUpdate = 1000000000.0 / 60;
// last update time in nano seconds
double then = System.nanoTime();
double unprocessed = 0;
while (running) {
boolean shouldRender = false;
double now = System.nanoTime();
unprocessed += (now - then) / nsPerUpdate;
then = now;
// update queque
while (unprocessed >= 1) {
update++;
update();
unprocessed--;
shouldRender = true;
}
// render
if (shouldRender) {
fps++;
render();
shouldRender = false;
} else {
try {
Thread.sleep(1);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public synchronized start(){
if(running)return;
running = true;
game = new Thread (this, "game");
game.start();
}
public synchronized stop (){
if(!running) return;
running = false;
System.exit(0);
}
#Override
public void keyTyped(KeyEvent e) {
}
#Override
public void keyPressed(KeyEvent e) {
}
#Override
public void keyReleased(KeyEvent e) {
}
}

I'm getting Thread [main] (Suspended (entry into method <init> in Game)) and I can't find the error anywhere

Thread [main] (Suspended (entry into method <init> in Game))
Game.<init>() line: 36
Game.main(String[]) line: 134
I keep receiving this error for some reason and I can't figure it out. all help appreciated
It says that there is some sort of error with the public Game() { and the new Game().start(); and I just can't find it
Here's my Game file:
package ca.vanzeben.game;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import javax.swing.JFrame;
import ca.vanzeben.game.gfx.Screen;
import ca.vanzeben.game.gfx.SpriteSheet;
public class Game extends Canvas implements Runnable {
private static final long serialVersionUID = 1L;
public static final int WIDTH = 160;
public static final int HEIGHT = WIDTH /12*9;
public static final int SCALE = 3;
public static final String NAME = "Wake Me Up...";
private JFrame frame;
public boolean running = false;
public int tickCount = 0;
private BufferedImage image = new BufferedImage(WIDTH,HEIGHT, BufferedImage.TYPE_INT_RGB);
private int[] pixels = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();
private Screen screen;
public Game() {
setMinimumSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
setMaximumSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
setPreferredSize(new Dimension(WIDTH*SCALE,HEIGHT*SCALE));
frame = new JFrame(NAME);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(this, BorderLayout.CENTER);
frame.pack();
frame.setResizable(false);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public void init() {
screen = new Screen(WIDTH,HEIGHT, new SpriteSheet("/SpriteSheet.png"));
}
public synchronized void start() {
running = true;
new Thread(this).start();
}
public synchronized void stop() {
running = false;
}
public void run() {
long lastTime = System.nanoTime();
double nsPerTick = 1000000000D / 60D;
int frames = 0;
int ticks = 0;
long lastTimer = System.currentTimeMillis();
double delta = 0;
init();
while (running) {
long now = System.nanoTime();
delta += (now - lastTime)/nsPerTick;
lastTime = now;
boolean ShouldRender = true;
while (delta >= 1) {
ticks++;
tick();
delta -= 1;
ShouldRender = true;
}
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (ShouldRender) {
frames++;
render();
}
if (System.currentTimeMillis()- lastTimer >= 1000){
lastTimer += 1000;
System.out.println(ticks+ "," +frames);
frames = 0;
ticks = 0;
}
}
}
public void tick() {
tickCount++;
for (int i = 0; i <pixels.length; i++) {
pixels[i] = i + tickCount;
}
}
public void render() {
BufferStrategy bs = getBufferStrategy();
if (bs == null) {
createBufferStrategy(3);
return;
}
screen.render(pixels, 0, WIDTH);
Graphics g = bs.getDrawGraphics();
g.drawImage(image, 0, 0, getWidth(), getHeight(),null);
g.dispose();
bs.show();
}
public static void main(String[] args){
new Game().start();
}
As I said, all help appreciated. It keeps saying that there's an error and I can't find it
You are using Eclipse, right?
You don't have an error, just a method entry breakpoint. Check the left bar beside the code. There will be a blue circle, with a tick and an arrow.
You have multiple options:
Double click that, it should go away (and restart execution, of course)
Right click, toggle: breakpoint goes away
Right click, disable: the breakpoint will be there, but not active
Instead of Debug (the green buggy button), use Run (green play button) -- breakpoints stay where they are, but not taken into acccount
pressing F8: breakpoints stay where they are, execution continues until next breakpoint
This does not look like an error. You are running your application inside a debugger or similar development tool which seems to be instructed to suspend your program at the specified location either by a breakpoint or a rule like “stop at instance creation”.
You should check your environment. Running with a plain java launcher does not produce such an error.

Categories