Results 1 to 8 of 8
- 10-30-2010, 04:15 PM #1
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
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
- 10-30-2010, 04:21 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,394
- Blog Entries
- 7
- Rep Power
- 17
- 10-30-2010, 05:02 PM #3
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
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);
}
}
- 10-30-2010, 05:26 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
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
- 10-30-2010, 09:31 PM #5
Member
- Join Date
- Oct 2010
- Posts
- 94
- Rep Power
- 0
Hi Mossy,
Have a close look at the constructor of your Screen class. Java is case sensitive...
Cheers,
Erik
- 10-30-2010, 11:28 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
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 :)
- 10-31-2010, 12:22 AM #7
Senior Member
- Join Date
- Mar 2009
- Posts
- 552
- Rep Power
- 5
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!
- 10-31-2010, 09:53 AM #8
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM -
getting an error Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/hu
By Hussain Ali in forum EclipseReplies: 8Last Post: 02-23-2010, 12:22 PM -
Runtime error "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
By shantimudigonda in forum New To JavaReplies: 1Last Post: 11-20-2009, 07:58 PM -
ERROR: Exception in thread "main" java.lang.NoSuchMethodError: main
By barney in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:10 AM -
Error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
By romina in forum New To JavaReplies: 1Last Post: 07-25-2007, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks