Results 1 to 18 of 18
  1. #1
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default javaw.exe Keeps encountering a problem, please help?

    i have been trying to create an application that will create a window (using JFrame) and then copy an image to it. I had it working until I created another class, i then encountered this problem of windows sending me a message of "javaw.exe has encountered a problem and has to close". i have now tried deleting this class and am still getting this error, any help?

    my code is as follows:

    ************************************************** ***************
    Java Code:
    //Game.java
    
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.io.File;
    import java.io.IOException;
    
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    
    public class Game {
    
    	
    	public static boolean running;
    	public static int tickCounter = 0;
    	public static Container frameContent;
    	private static Screen inventory;
    	
    	public static boolean tick() {
    		tickCounter++;
    		return running;		
    	}
    
    	public static void render(JFrame frame, Canvas canvas) {
    	    Graphics2D g2D= (Graphics2D) canvas.getGraphics();
    	    g2D.setColor(Color.BLACK);
    	    g2D.drawRect(40, 40, 40, 40);
    	    g2D.drawImage(inventory.getImage(), 10, 10, 16, 16, null);
    	}	
    	  
    	public static void logic() {
    	}
    	
    	public static void main(String[] args)  throws IOException {
    		// set up main frame called "Game Window"
    		JFrame.setDefaultLookAndFeelDecorated(true);
    		JFrame mainFrame = new JFrame("Game Window");
    		frameContent = mainFrame.getContentPane();
    		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		
    		mainFrame.setBounds(0, 0, 640, 480);
    		mainFrame.setSize(640, 480);
    		mainFrame.setLocationRelativeTo(null);
    		
    		frameContent.setBackground(Color.WHITE);
    		Canvas frameCanvas = new Canvas();
    		frameContent.add(frameCanvas);
    		mainFrame.setVisible(true);
    		//end of setting up main window
    
    		Image icon = frameCanvas.createImage(16, 16);
    		icon = ImageIO.read(new File("img/icon.png"));
    		
    		inventory = new Screen(520, 0, 120, 480);
    		inventory.init();
    		inventory.copyImage(icon, 10, 10);
    		
    		running = true;
    		
    		while(tick()) {
    			logic();
    			render(mainFrame, frameCanvas);
    		}
    		mainFrame.dispose();
    	}
    
    }
    
    ****************************************************************
    
    
    ****************************************************************
    //Screen.java
    
    import java.awt.Canvas;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Rectangle;
    
    
    public class Screen {
    	private Image screenImage;
    	private Rectangle screenRect;
    	private Graphics2D screenGraphics;
    	
    	public Screen(int x, int y, int width, int height) {
    		System.out.println("x: "+x+", y: "+y+", width: "+width+", height: "+height);
    		this.screenRect = new Rectangle(x, y, width, height);
    	}
    
    	public Image getImage() {
    		return this.screenImage;
    	}
    
    	public void copyImage(Image img, int x, int y) {
    		this.screenGraphics.drawImage(img, x, y, null);
    	}
    
    	public void init() {
    		Canvas screenCanvas = new Canvas();
    		this.screenImage = screenCanvas.createImage(this.screenRect.width, this.screenRect.height);
    		this.screenGraphics = (Graphics2D) this.screenImage.getGraphics();	
    	}
    
    	
    }
    ************************************************** **************
    Last edited by Norm; 08-21-2011 at 10:39 PM. Reason: added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    problem of windows sending me a message of "javaw.exe has encountered a problem and has to close
    That sounds bad. Can you execute the program using the java command in a command prompt window and copy the contents of the screen here?
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    C:\my\bin>java Game
    Exception in thread "main" javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(Unknown Source)
    at Game.main(Game.java:53)

  4. #4
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    I hope thats helpful

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    IIOException: Can't read input file!
    Where is the file the program is trying to read? Check that the file is where it is supposed to be and that the path and name are spelled correctly.

  6. #6
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    yep they were, however in order to ensure this didnt stop the program i changed the code, the new code is :

    ************************************************** *********************************************
    //Game.java
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.io.File;
    import java.io.IOException;

    import javax.imageio.ImageIO;
    import javax.swing.JFrame;

    public class Game {


    public static boolean running;
    public static int tickCounter = 0;
    public static Container frameContent;

    public static boolean tick() {
    tickCounter++;
    return running;
    }

    public static void render(JFrame frame, Canvas canvas) {
    Graphics2D g2D= (Graphics2D) canvas.getGraphics();
    g2D.setColor(Color.BLACK);
    g2D.drawRect(40, 40, 40, 40);
    }

    public static void logic() {
    }

    public static void main(String[] args) throws IOException {
    // set up main frame called "Game Window"
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame mainFrame = new JFrame("Game Window");
    frameContent = mainFrame.getContentPane();
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_ CLOSE);

    mainFrame.setBounds(0, 0, 640, 480);
    mainFrame.setSize(640, 480);
    mainFrame.setLocationRelativeTo(null);

    frameContent.setBackground(Color.WHITE);
    Canvas frameCanvas = new Canvas();
    frameContent.add(frameCanvas);
    mainFrame.setVisible(true);
    //end of setting up main window

    running = true;

    while(tick()) {
    logic();
    render(mainFrame, frameCanvas);
    }
    mainFrame.dispose();
    }

    }

    ************************************************** *********************************

    and when i run it using cmd i get nothing returned but still the same "encountered an error" message

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Please copy and paste here the contents of the command prompt screen.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Please edit your code and wrap it in code tags. Use the # icon above the input box.

  9. #9
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    it doesn't say anything i have:

    mydirectory>java Game

    then the program opens, throws me that message and closes with nothing on the command prompt

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Is this the only program you have this problem with?
    Do other java programs work ok?

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Can you describe what your program is supposed to do?
    The forever loop in the main method looks like a very bad idea.

  12. #12
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    no i just rewrote another program that just displayed a JFrame that also gave me the same message,
    the code i wrote:
    Java Code:
    import javax.swing.JFrame;
    
    
    public class screen {
    
    	public static void main(String[] args) {
    		JFrame myFrame = new JFrame("Hello");
    		myFrame.setSize(200, 200);
    		myFrame.setVisible(true);
    	}
    
    }

  13. #13
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Could be something wrong with your java installation.

  14. #14
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    I'm planning to make it into a game, the while loop being the main loop that the game cycles through

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Your should move the logic out of the main method and put a forever running loop in its own thread.

  16. #16
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    okay, thank you for the advice, i am just re-installing jaava to see if this helps, i will post the outcome as soon as, as far as the loopp goes, to be honest im new to all this so am unsure how to create different threads, as this is the way i would of done it in other languages this is why i have done it like this, however following your advice i will be sure to research this further and give it a go, thank you

  17. #17
    MattRussell is offline Member
    Join Date
    Aug 2011
    Posts
    9
    Rep Power
    0

    Default

    thank you for your help Norm, i installed JDK 7 and its now working fine

  18. #18
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

Similar Threads

  1. javaw cpu
    By trishtren in forum New To Java
    Replies: 1
    Last Post: 04-18-2011, 02:13 PM
  2. javaw.exe problem in Task Manager
    By sarwar1234 in forum New To Java
    Replies: 5
    Last Post: 09-30-2010, 01:47 AM
  3. javaw.exe running jbroker.exe?????
    By fxRichard in forum Advanced Java
    Replies: 3
    Last Post: 05-11-2009, 11:09 PM
  4. My first Java project, encountering bugs
    By beatzz in forum New To Java
    Replies: 1
    Last Post: 03-17-2009, 08:32 PM
  5. Replies: 6
    Last Post: 01-11-2009, 03:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •