1

Errors in my 2d Java Game

ItsScootz 8/28/14 3:58 pm
884
8/29/2014 4:44 pm
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
Level 15 : Journeyman Artist
20

  Have something to say?

JoinSign in

34

GFX
08/29/2014 5:39 am
Level 2 : Apprentice Crafter
Oh you have no source code linked to the main code.
1
anonpmc844841
08/28/2014 11:20 pm
Level 13 : Journeyman Miner
[deleted]
1
nickfromgreece
08/29/2014 5:37 am
Level 54 : Grandmaster Programmer
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
gabe4356
08/29/2014 4:44 pm
Level 53 : Grandmaster Blob
I actually started with eclipse. xD
1
ItsScootz
08/28/2014 11:11 pm
Level 15 : Journeyman Artist
On topic..
1
Histor the Noob
08/28/2014 6:58 pm
Level 28 : Expert Geek
. . . . . . . . . . . . . . . . . . . ________
. . . . . .. . . . . . . . . . . ,.-‘”. . . . . . . . . .``~.,
. . . . . . . .. . . . . .,.-”. . . . . . . . . . . . . . . . . .“-.,
. . . . .. . . . . . ..,/. . . . . . . . . . . . . . . . . . . . . . . ”:,
. . . . . . . .. .,?. . . . . . . . . . . . . . . . . . . . . . . . . . .\,
. . . . . . . . . /. . . . . . . . . . . . . . . . . . . . . . . . . . . . ,}
. . . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . . ,:`^`.}
. . . . . . . ./. . . . . . . . . . . . . . . . . . . . . . . . . ,:”. . . ./
. . . . . . .?. . . __. . . . . . . . . . . . . . . . . . . . :`. . . ./
. . . . . . . /__.(. . .“~-,_. . . . . . . . . . . . . . ,:`. . . .. ./
. . . . . . /(_. . ”~,_. . . ..“~,_. . . . . . . . . .,:`. . . . _/
. . . .. .{.._$;_. . .”=,_. . . .“-,_. . . ,.-~-,}, .~”; /. .. .}
. . .. . .((. . .*~_. . . .”=-._. . .“;,,./`. . /” . . . ./. .. ../
. . . .. . .\`~,. . ..“~.,. . . . . . . . . ..`. . .}. . . . . . ../
. . . . . .(. ..`=-,,. . . .`. . . . . . . . . . . ..(. . . ;_,,-”
. . . . . ../.`~,. . ..`-.. . . . . . . . . . . . . . ..\. . /\
. . . . . . \`~.*-,. . . . . . . . . . . . . . . . . ..|,./.....\,__
,,_. . . . . }.>-._\. . . . . . . . . . . . . . . . . .|. . . . . . ..`=~-,
. .. `=~-,_\_. . . `\,. . . . . . . . . . . . . . . . .\
. . . . . . . . . .`=~-,,.\,. . . . . . . . . . . . . . . .\
. . . . . . . . . . . . . . . . `:,, . . . . . . . . . . . . . `\. . . . . . ..__
. . . . . . . . . . . . . . . . . . .`=-,. . . . . . . . . .,%`>--==``
. . . . . . . . . . . . . . . . . . . . _\. . . . . ._,-%. . . ..`\
Trial and error.
1
ItsScootz
08/28/2014 6:44 pm
Level 15 : Journeyman Artist
Please, keep this on topic >.>
1
ItsScootz
08/28/2014 6:39 pm
Level 15 : Journeyman Artist
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
xAstraah
08/28/2014 6:37 pm
Level 18 : Journeyman Modder
Java Swing is now being taken over to JavaFX now in Java 8 +
1
GigabyteGiant
08/28/2014 6:43 pm
Level 42 : Master Droid
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
Jas
08/28/2014 6:33 pm
Level 67 : High Grandmaster Sweetheart
How come you've called the "setMinimumSize()" method twice with the same arguments?

- Slendy
1
nickfromgreece
08/28/2014 6:27 pm
Level 54 : Grandmaster Programmer
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
GigabyteGiant
08/28/2014 6:25 pm
Level 42 : Master Droid
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
nickfromgreece
08/28/2014 6:21 pm
Level 54 : Grandmaster Programmer
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
ItsScootz
08/28/2014 6:19 pm
Level 15 : Journeyman Artist
I said I have no previous coding experience. I really need your help though, guys.
1
ItsScootz
08/28/2014 5:52 pm
Level 15 : Journeyman Artist
k
1
ItsScootz
08/28/2014 5:47 pm
Level 15 : Journeyman Artist
what is that lol
1
Find Them Creepers
08/28/2014 5:48 pm
Level 34 : Artisan Dragon
I wouldn't suggest making a 2D game if you don't know what a main class is, lol
1
anonpmc844841
08/28/2014 6:34 pm
Level 13 : Journeyman Miner
[deleted]
1
gabe4356
08/28/2014 5:50 pm
Level 53 : Grandmaster Blob
Lolz
1
gabe4356
08/28/2014 5:43 pm
Level 53 : Grandmaster Blob
not yet, but you just need to select a main class for it
1
ItsScootz
08/28/2014 5:35 pm
Level 15 : Journeyman Artist
Any luck?
1
ItsScootz
08/28/2014 5:21 pm
Level 15 : Journeyman Artist
1
gabe4356
08/28/2014 5:21 pm
Level 53 : Grandmaster Blob
Ok, I will try to fix that then
1
ItsScootz
08/28/2014 5:17 pm
Level 15 : Journeyman Artist
I tried your game. Running it had the same effects. If we can resolve those, then ill continue my tutorials i'm using.
1
gabe4356
08/28/2014 5:15 pm
Level 53 : Grandmaster Blob
Sent it
1
ItsScootz
08/28/2014 5:15 pm
Level 15 : Journeyman Artist
Oki doke. xDD
1
gabe4356
08/28/2014 5:03 pm
Level 53 : Grandmaster Blob
Hmm...I will just PM you the src code for my game, xD You can edit it
1
gabe4356
08/28/2014 5:01 pm
Level 53 : Grandmaster Blob
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
gabe4356
08/28/2014 4:51 pm
Level 53 : Grandmaster Blob
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
ItsScootz
08/28/2014 4:56 pm
Level 15 : Journeyman Artist
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
ItsScootz
08/28/2014 4:44 pm
Level 15 : Journeyman Artist
[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
gabe4356
08/28/2014 4:40 pm
Level 53 : Grandmaster Blob
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
ItsScootz
08/28/2014 4:29 pm
Level 15 : Journeyman Artist
Help?
1

Welcome