10 Replies - 3519 Views - Last Post: 04 October 2012 - 09:41 AM Rate Topic: -----

#1 Zodiacx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-October 12

Problems running Java in Eclipse

Posted 03 October 2012 - 03:24 PM

Hi there,
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.

Is This A Good Question/Topic? 0
  • +

Replies To: Problems running Java in Eclipse

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 03:30 PM

What's the name of the top-level public class? What's the name of the file it's stored in? Post the code (not script) in code tags.
Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,531
  • Joined: 29-July 11

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 03:39 PM

Post your code. Doesn't look like an eclipse problem.

This post has been edited by farrell2k: 03 October 2012 - 03:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 Zodiacx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-October 12

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.
Was This Post Helpful? 0
  • +
  • -

#5 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,531
  • Joined: 29-July 11

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 03:44 PM

Are you adding this Canvas to a JFrame and getting this error when you execute your app?

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

Was This Post Helpful? 0
  • +
  • -

#6 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2198
  • View blog
  • Posts: 5,226
  • Joined: 10-September 10

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 03:48 PM

You have a few typos:

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

Was This Post Helpful? 0
  • +
  • -

#7 Zodiacx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-October 12

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 03:49 PM

This is my GameFrame which I hope you wanted;

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.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 08:37 PM

If you set your JFrame setIgnoreRepaint(true) you will have to find another way to refresh/repaint your Canvas :)

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

Was This Post Helpful? 0
  • +
  • -

#9 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,531
  • Joined: 29-July 11

Re: Problems running Java in Eclipse

Posted 03 October 2012 - 09:13 PM

View Postpbl, on 04 October 2012 - 03:37 AM, said:

If you set your JFrame setIgnoreRepaint(true) you will have to find another way to refresh/repaint your Canvas :)


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.
Was This Post Helpful? 1
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8327
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Problems running Java in Eclipse

Posted 04 October 2012 - 04:40 AM

GameCanvas will still have to call repaint() on the JFrame
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
Was This Post Helpful? 0
  • +
  • -

#11 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,531
  • Joined: 29-July 11

Re: Problems running Java in Eclipse

Posted 04 October 2012 - 09:41 AM

Nah. AWT will still figure out when the JFrame and its children are dirty and need to be repainted. You can verify that by overriding paint on the JFrame and doing some logging in there.

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...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1