Problems running Java in Eclipse
Page 1 of 110 Replies - 698 Views - Last Post: 04 October 2012 - 09:41 AM
#1
Problems running Java in Eclipse
Posted 03 October 2012 - 03:24 PM
Sorry if I'm wrong; I'm just quite new here.
This is the error I get when I right click > Run As > Run configurations > Java Application > New_Configuration > Run and this is what I get;
Error: Could not find or load main class 2D
It says this at the top of the console;
<terminated> New_configuration[Java Application]C:\Program Files (x86)\Java\jre7\bin\javaw.exe
What can I do to fix this? If you need what coding scripts I have, I will happily provide them.
Zodiac.
Replies To: Problems running Java in Eclipse
#2
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 03:30 PM
#3
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 03:39 PM
This post has been edited by farrell2k: 03 October 2012 - 03:40 PM
#4
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 03:41 PM
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
public class GameCanvas extends Canvas implements Runnable {
int FWidth = 800;
int FHeight = 600;
public long period = 10;
public BufferStrategy Buffer;
public Graphics graphics;
private Thread t;
public GameCanvas() {
this.setIgnoreRepaint(true);
this.setBounds(0, 0, FWidth, FHeight);
this.setBackground(Color.white);
this.setVisible(true);
}
public void addNotify() {
supper.addNotify();
this.createBufferStrategy(2);
this.Buffer = this.getBufferStrategy();
requestFocus();
startGame();
}
public void startGame() {
if (t == null) {
t == new Thread(this);
t.start();
}
}
public void run() {
while(true) {
long beginTime = System.currentTimeMillis();
Update();
Render();
Draw();
long timeTaken = System.currentTimeMillis();
long sleepTime = period - timeTaken;
try {
t.sleep(sleepTime);
}
catch(Exception e) {
}
}
}
public void Update() {
// logic of the game. wierd, eh?
}
public void Render() {
graphics = Buffer.getDrawGraphics();
graphics.setColor(Color.white);
graphics.fillRect(0, 0, FWidth, FHeight)
// Paint stuff o:
}
public void Draw() {
if(!Buffer.contentsLost())
Buffer.show();
if(!graphics != null){
graphics.dispose();
}
}
}
}
This is my Java that I am trying. I have two more scripts but this is what I attempted to run. The others give similar feedback.
#5
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 03:44 PM
I have a feeling that you have a class somewhere with an empty main(), and nothing is being executed.
This post has been edited by farrell2k: 03 October 2012 - 03:46 PM
#6
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 03:48 PM
line 26: supper ?
line 35: ==
Color isn't defined.
line 88: illegal statement, !graphics
too many close braces
Eclipse is trying to tell you about these errors with its squigglies.
I don't see the source of the error you posted, no sign of a class called "2D".
No problems with Eclipse or libraries missing that I can see, but it's possible that you haven't imported something needed, but it's not evident in the code you posted.
Edit: Oh! Also, no main() method, so what you posted won't run.
This post has been edited by GregBrannon: 03 October 2012 - 03:52 PM
#7
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 03:49 PM
import javax.swing.JFrame;
public class GameFrame {
public static void main($tring args[]) {
int FWidth = 800;
int FHeight = 600;
JFrame frame = new JFrame("2D Game");
frame.setIgnoreRepaint(true);
frame.setBounds(0, 0, FWidth, FHeight);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GameCanvas game = new GameCanvas();
frame.add(game);
frame.setVisible(true);
}
}
You could well be right there. These are my only two that are completed at this point.
#8
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 08:37 PM
This post has been edited by pbl: 04 October 2012 - 04:41 AM
Reason for edit:: Seems it was my bad but look two posts below
#9
Re: Problems running Java in Eclipse
Posted 03 October 2012 - 09:13 PM
pbl, on 04 October 2012 - 03:37 AM, said:
Nah. setIgnoreRepaint() ONLY ignores paint requests from the OS. It won't affect software driven requests, such as calling repaint() in your code. It's really only useful for fullscreen apps when using a bufferstrategy.
#10
Re: Problems running Java in Eclipse
Posted 04 October 2012 - 04:40 AM
as the JFrame is a local variable, and as it is not passed as parameter to the GameCanvas constructor it is not accessible so any repaint() of the JFrame won't be possible
#11
Re: Problems running Java in Eclipse
Posted 04 October 2012 - 09:41 AM
The bigger question is, because AWT knows nothing about when his custom thread is painting that canvas every x millis, will he ever have a deadlock when both his Canvas and AWT try to paint at the same time, or is only one graphics object allowed to paint at any given time? I don't know...
|
|

New Topic/Question
Reply



MultiQuote




|