Results 1 to 8 of 8
  1. #1
    mossy is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default Exception in thread "main" java.lang.Error ...

    Hi!
    I VERY new to Java but frustratingly I'm having an issue with compiling some code that should work. I've been working through the excellent tutorials by Bucky.


    I've got to the one where he describes how to set up a screen ready to draw to:

    (the code found in these excellent tutorials):

    YouTube - Java Game Development - 3 - Creating a Screen for Games
    YouTube - Java Game Development - 4 - Restoring Screen Size
    YouTube - Java Game Development - 5 - Creating a Full Screen Display

    The problem is when I try to compile and run it I get this error:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at Drawing.main(Draw.java:8)

    No one else seems to be getting this issue, and I'm really not skilled enough yet in Java to have any idea what the problem could be. Has any one got any ideas?

    I've downloaded the absolute latest Java devkit, so I'm wondering if they've changed something in it so this code won't run anymore.

    If you can help I'll be extremely grateful! :D

    thanks

    Mossy

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,679
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by mossy View Post
    The problem is when I try to compile and run it I get this error:

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:

    at Drawing.main(Draw.java:8)
    You get that error when you try to run an incorrect .class file; you have ignored the error message issued by the compiler. Show us that compiler message and the bit of relevant code.

    kind regards,

    Jos

  3. #3
    mossy is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    opps! Sorry about that :) Here's the error message in full, and the accompanying by the code from the two accompanying java files that I copied from the Bucky tutorial (I've checked it and rewritten it a couple of times so I'm fairly sure it's correct):

    Exception in thread "main" java.lang.NullPointerException
    at Screen.restoreScreen(Screen.java:30)
    at bucky.run(bucky.java:26)
    at bucky.main(bucky.java:10)

    thanks for the help :)

    Mossy


    bucky.java file:
    ---------------

    import java.awt.*;
    import javax.swing.JFrame;
    import java.awt.Font;

    public class bucky extends JFrame {
    public static void main(String[] args) {

    DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN);
    bucky b = new bucky();
    b.run(dm);
    // paint;
    }

    public void run(DisplayMode dm){
    setBackground(Color.PINK);
    setForeground(Color.WHITE);
    setFont(new Font("Arial", Font.PLAIN, 24));

    Screen s = new Screen();
    try{
    s.setFullScreen(dm, this);
    try{
    Thread.sleep(5000);
    }catch (Exception ex){}
    }finally{
    s.restoreScreen();
    }

    }

    public void paint(Graphics g){

    //g.clearRect(0,0,getWidth(),getHeight());
    g.drawString("TEST TEXT", 200,200);
    }

    }


    screen.java file:
    ---------------

    import java.awt.*;
    import javax.swing.JFrame;

    public class Screen {

    private GraphicsDevice vc;

    public screen(){
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    vc = env.getDefaultScreenDevice();
    }

    public void setFullScreen(DisplayMode dm, JFrame window){
    window.setUndecorated(true);
    window.setResizable(false);
    vc.setFullScreenWindow(window);

    if(dm != null && vc.isDisplayChangeSupported()){
    try{
    vc.setDisplayMode(dm);
    }catch(Exception ex){}
    }
    }

    public Window getFullScreenWindow(){
    return vc.getFullScreenWindow();
    }

    public void restoreScreen(){
    Window w = vc.getFullScreenWindow();
    if (w!= null){
    w.dispose();
    }
    vc.setFullScreenWindow(null);
    }

    }

  4. #4
    mossy is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    Sorry, here's the actual error messages (still finding my around Eclipse): :)
    Description Resource Path Location Type
    Return type for the method is missing Screen.java /ScreenStuff/src line 8 Java Problem
    The public type Screen must be defined in its own file Blitz.java /Mosiac/src line 4 Java Problem
    The serializable class bucky does not declare a static final serialVersionUID field of type long bucky.java /Mosiac/src line 6 Java Problem
    The serializable class bucky does not declare a static final serialVersionUID field of type long bucky.java /ScreenStuff/src line 5 Java Problem

  5. #5
    venerik is offline Member
    Join Date
    Oct 2010
    Posts
    94
    Rep Power
    0

    Default

    Hi Mossy,

    Have a close look at the constructor of your Screen class. Java is case sensitive...

    Cheers,
    Erik

  6. #6
    mossy is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    thanks for the tip :) I've taken a quick look but everything seems to be in place. Out of interest would it be possible to try out those bits of code I've included in the post above. I'm wondering if my Java has been set up incorrectly somehow and this is causing the issue.

    thanks

    Mossy :)

  7. #7
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Apparently Screen is declared in the Blitz.java file... not good xD (and the aforementioned case problem... public screen() should be public Screen()) Other than that, doesn't look like there are any fatal compiler errors. (Including the SVUIDs is a good idea, but not necessary... do that later.)
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  8. #8
    mossy is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Replies: 5
    Last Post: 06-22-2010, 04:51 PM
  2. Replies: 8
    Last Post: 02-23-2010, 01:22 PM
  3. Replies: 1
    Last Post: 11-20-2009, 08:58 PM
  4. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 11:55 PM

Posting Permissions

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