Hi Guys,
lets get straight to the point. I have this problem:
Exception in thread "Thread-2" java.lang.NullPointerException
at javax.swing.JComponent.getComponentGraphics(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at Display.Display.run(Display.java:39)
at java.lang.Thread.run(Unknown Source)
So.. here is my code for one class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| package Display;
import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferStrategy;
import javax.swing.JPanel;
public class Display extends JPanel implements Runnable {
private Graphics g; private Thread gameThread; private boolean running = false;
public Display() { gameThread = new Thread(); }
public void init() { running = true; gameThread = new Thread(this); gameThread.start();
}
public void update() {
}
public void draw(Graphics g){ }
@Override public void run() { while (running) { update(); paint(g); } }
} |
and the other class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| package fullscreen;
import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment;
import javax.swing.JFrame;
import Display.Display;
public class MainFrame extends JFrame {
private static final long serialVersionUID = -485903859773002276L; private GraphicsDevice device; private boolean isFullScreen = false; private Display display = new Display();
public MainFrame(GraphicsDevice device) { setTitle("SeemRang Fullscreen API"); setDefaultCloseOperation(EXIT_ON_CLOSE);
this.device = device;
add(display); display.init(); }
public void begin() { isFullScreen = device.isFullScreenSupported(); setUndecorated(isFullScreen); setResizable(!isFullScreen);
if (isFullScreen) { device.setFullScreenWindow(this); } else { pack(); setVisible(true); } }
public static void main(String[] args) { GraphicsEnvironment env = GraphicsEnvironment .getLocalGraphicsEnvironment(); GraphicsDevice[] devices = env.getScreenDevices();
for (int i = 0; i < 1; i++) { MainFrame test = new MainFrame(devices[i]); test.begin(); } } } |
and the last.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| package fullscreen;
import java.awt.DisplayMode;
public class FullscreenInit { private DisplayMode modes;
public FullscreenInit(DisplayMode modes) { this.modes = modes; }
public DisplayMode getDisplayMode() { return modes; }
} |
any solutions??? Any help will be appreciated.
Thnx,
LucaSeem
