1

Errors in my 2d Java Game

ItsScootz's Avatar ItsScootz8/28/14 3:58 pm
8/29/2014 4:44 pm
gabe4356's Avatar gabe4356
Im making a 2d Java Game using Eclipse. I have no real previous coding experience. I am trying to run it in the debug mode. this is the error when I try to run it.



This is the code:





Could someone tell me whats wrong, and how I can resolve these problems?
Posted by ItsScootz's Avatar
ItsScootz
Level 15 : Journeyman Artist
20

Create an account or sign in to comment.

34

1
08/29/2014 5:39 am
Level 2 : Apprentice Crafter
GFX
GFX's Avatar
Oh you have no source code linked to the main code.
1
08/28/2014 11:20 pm
Level 14 : Journeyman Modder
searchndstroy
searchndstroy's Avatar
You forgot to put your class in a package!
1
08/29/2014 5:37 am
Level 54 : Grandmaster Programmer
nickfromgreece
nickfromgreece's Avatar
It is in a package....


Also OP starting out if you dont want to get confused with IDEs I would suggest you simply start out with the old fashioned notepad + compiler setup.
1
08/29/2014 4:44 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
I actually started with eclipse. xD
1
08/28/2014 11:11 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
On topic..
1
08/28/2014 6:58 pm
Level 28 : Expert Geek
Histor the Noob
Histor the Noob's Avatar
. . . . . . . . . . . . . . . . . . . ________
. . . . . .. . . . . . . . . . . ,.-‘”. . . . . . . . . .``~.,
. . . . . . . .. . . . . .,.-”. . . . . . . . . . . . . . . . . .“-.,
. . . . .. . . . . . ..,/. . . . . . . . . . . . . . . . . . . . . . . ”:,
. . . . . . . .. .,?. . . . . . . . . . . . . . . . . . . . . . . . . . .\,
. . . . . . . . . /. . . . . . . . . . . . . . . . . . . . . . . . . . . . ,}
. . . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . . ,:`^`.}
. . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . ,:”. . . ./
. . . . . . .?. . . __. . . . . . . . . . . . . . . . . . . . :`. . . ./
. . . . . . . /__.(. . .“~-,_. . . . . . . . . . . . . . ,:`. . . .. ./
. . . . . . /(_. . ”~,_. . . ..“~,_. . . . . . . . . .,:`. . . . _/
. . . .. .{.._$;_. . .”=,_. . . .“-,_. . . ,.-~-,}, .~”; /. .. .}
. . .. . .((. . .*~_. . . .”=-._. . .“;,,./`. . /” . . . ./. .. ../
. . . .. . .\`~,. . ..“~.,. . . . . . . . . ..`. . .}. . . . . . ../
. . . . . .(. ..`=-,,. . . .`. . . . . . . . . . . ..(. . . ;_,,-”
. . . . . ../.`~,. . ..`-.. . . . . . . . . . . . . . ..\. . /\
. . . . . . \`~.*-,. . . . . . . . . . . . . . . . . ..|,./.....\,__
,,_. . . . . }.>-._\. . . . . . . . . . . . . . . . . .|. . . . . . ..`=~-,
. .. `=~-,_\_. . . `\,. . . . . . . . . . . . . . . . .\
. . . . . . . . . .`=~-,,.\,. . . . . . . . . . . . . . . .\
. . . . . . . . . . . . . . . . `:,, . . . . . . . . . . . . . `\. . . . . . ..__
. . . . . . . . . . . . . . . . . . .`=-,. . . . . . . . . .,%`>--==``
. . . . . . . . . . . . . . . . . . . . _\. . . . . ._,-%. . . ..`\
Trial and error.
1
08/28/2014 6:44 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
Please, keep this on topic >.>
1
08/28/2014 6:39 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
So, er, I really don't know how to do this... I don't know Eclipse, and I have never coded before. I'm making this 100% from a tutorial, until I finish it, then I'll get more help, and learn.
1
08/28/2014 6:37 pm
Level 18 : Journeyman Modder
xAstraah
xAstraah's Avatar
Java Swing is now being taken over to JavaFX now in Java 8 +
1
08/28/2014 6:43 pm
Level 42 : Master Droid
GigabyteGiant
GigabyteGiant's Avatar
JavaFX is awesome IMO.

And I agree with others, maybe you should learn basic Java before trying to make an sort of game. Even if you are going off of a tutorial...
1
08/28/2014 6:33 pm
Level 67 : High Grandmaster Sweetheart
Jas
Jas's Avatar
How come you've called the "setMinimumSize()" method twice with the same arguments?

- Slendy
1
08/28/2014 6:27 pm
Level 54 : Grandmaster Programmer
nickfromgreece
nickfromgreece's Avatar
Also just noticed, you are closing off the Game class at line 12 but then you keep adding on fields and methods... why in the world hasn't the syntax checker screamed at you.
1
08/28/2014 6:25 pm
Level 42 : Master Droid
GigabyteGiant
GigabyteGiant's Avatar
That error is caused when you don't have a main method...

That or, you need to specify the class to launch, but, make sure the aforementioned class contains a main method.
1
08/28/2014 6:21 pm
Level 54 : Grandmaster Programmer
nickfromgreece
nickfromgreece's Avatar
Click to reveal
Are you using any frameworks/libraries?

I am using IntelliJ IDEA and cant remember how eclipses' GUI is but from the messages it looks like you haven't selected which class has the main method.

If you are using a library check the wiki for that, else select the class with the
public void main(String[] args) {} method

EDIT:

Ah you are doing this totally wrong just read your code from your screenshots.

You are using javas swing packages as I see and it doesnt apear to have a main method.

Add in a method named main with a string array as arguments
public void main(String[] args){

}


The code in that method is the code that will run when the program is executed.
1
08/28/2014 6:19 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
I said I have no previous coding experience. I really need your help though, guys.
1
08/28/2014 5:52 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
k
1
08/28/2014 5:47 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
what is that lol
1
08/28/2014 5:48 pm
Level 34 : Artisan Dragon
Find Them Creepers
Find Them Creepers's Avatar
I wouldn't suggest making a 2D game if you don't know what a main class is, lol
1
08/28/2014 6:34 pm
Level 14 : Journeyman Modder
searchndstroy
searchndstroy's Avatar
^^^^^^^^^
1
08/28/2014 5:50 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Lolz
1
08/28/2014 5:43 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
not yet, but you just need to select a main class for it
1
08/28/2014 5:35 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
Any luck?
1
08/28/2014 5:21 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
1
08/28/2014 5:21 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Ok, I will try to fix that then
1
08/28/2014 5:17 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
I tried your game. Running it had the same effects. If we can resolve those, then ill continue my tutorials i'm using.
1
08/28/2014 5:15 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Sent it
1
08/28/2014 5:15 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
Oki doke. xDD
1
08/28/2014 5:03 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Hmm...I will just PM you the src code for my game, xD You can edit it
1
08/28/2014 5:01 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Ok, I know that error as well, I despise it...I just want it to go die in a hole and...I think you get it. I forgot how to fix that, let me go expieriment
1
08/28/2014 4:51 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
Oh, that is not a problem with the code! xD Let me run you through this, just right click on the Java Project > Run As > Java Application
1
08/28/2014 4:56 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
I used a tutorial to get this far, just to set up the JFrame. He didn't do that to run it, he did it through the debug run. Also, this error occurred when I did it.
1
08/28/2014 4:44 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
[quote="gabe4356"]It would be a lot eaiser to help you if you just put the code in a spoiler.

Sorry, I put it in a image because I thought words that were highlighted automatically mattered. This is the code.'

[spoiler]package ca.vanzeben.adventure;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;

import javax.swing.JFrame

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 = "Adventure!"

private JFrame frame;

public boolean running = false;

public Game() {
setMinimumSize(new Dimension(WIDTH * SCALE, HEIGHT * SCALE));
setMinimumSize(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 synchronized void start() {
running = true;
new Thread(this).start();
}

public synchronized void stop() {
running = false;

}

public void run() {
while (running) {
System.out.printIn("Hello World");
}
}

public static void main(String[] args) {
new Game().start()
}[/spoiler]
1
08/28/2014 4:40 pm
Level 52 : Grandmaster Blob
gabe4356
gabe4356's Avatar
It would be a lot eaiser to help you if you just put the code in a spoiler or something like this:
Click to reveal
INSERT CODE HERE
1
08/28/2014 4:29 pm
Level 15 : Journeyman Artist
ItsScootz
ItsScootz's Avatar
Help?
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome