Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Code is giving an error in console, but there are no errors apparent in the code!

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    37
    My Mood
    Where
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Code is giving an error in console, but there are no errors apparent in the code!

    Basically, I am trying to drawString and I am getting some unexplained errors. Eclipse isn't redlining anything, but when I run the application, it gives an error and refuses to draw the test. Here is my source code:

    MainGameClass:

    public class MainGameClass {
     
    	//Accesses the ScreenHandler class and makes it use 'sh' variable
    	static ScreenHandler sh = new ScreenHandler();
     
    	//Main thingy (duh)
    	public static void main(String[] args) {
     
    		//Makes ScreenHandler class activate DrawWindow method
    		sh.DrawWindow();
    		sh.PaintWindowText(null);
     
    	}
     
    }

    ScreenHandler

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
     
    import javax.swing.JFrame;
    import javax.swing.JLabel;
     
    //Referenced by MainGameClass
     
    public class ScreenHandler {
     
    	//Draws the window the game is in
    	JFrame frame = new JFrame("Indev v0.01");
     
    	public void DrawWindow(){
    		//Initiates window drawing
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    		JLabel emptyLabel = new JLabel("");
    		//Makes it 800 by 600
    		emptyLabel.setPreferredSize(new Dimension(1000, 600));
    		frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);
     
    		frame.pack();
    		//Makes it visible
    		frame.setVisible(true);
     
    		//Activates the PaintWindow function below
    		PaintWindowColor();
     
    	}
    	public void PaintWindowColor(){
     
    		//Sets the background color to blue
    		//frame.getContentPane().setBackground(Color.BLUE);
    	}
    	public void PaintWindowText(Graphics g){
     
    		if(g instanceof Graphics2D){
     
    		}
    		try{
    		g.drawString("Did this work?", 200, 200);
    		} catch (Exception ex)
    		{
    			ex.printStackTrace();
    		}
    		//Makes a new JLabel with text in it
    		//JLabel label = new JLabel("Did this work?");
     
    		//Sets the font to plain
    		//label.setFont(new Font("Sans-Serif",Font.PLAIN,140));
     
    		//Adds the text label to the screen
    		//frame.add(label);
    	}
    }

    I hope you can help, as any guidance would be greatly appreciated!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Code is giving an error in console, but there are no errors apparent in the code!

    and the error message is.....
    Improving the world one idiot at a time!

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Code is giving an error in console, but there are no errors apparent in the code!

    Please do not duplicate posts. I am locking this thread. Please keep all discussions to the original thread you started:
    http://www.javaprogrammingforums.com...rawstring.html

Similar Threads

  1. I still have errors. Can you PLEASE correct my code?!
    By sam30317 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 6th, 2011, 06:10 AM
  2. JavaCompilerobject giving an error WITHOUT ide
    By divs1210 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2011, 08:49 PM
  3. Error with code
    By JJTierney in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2010, 05:23 PM
  4. Please check the code for the errors
    By nrao in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 16th, 2010, 05:37 PM
  5. Replies: 0
    Last Post: March 5th, 2010, 01:32 AM