java.lang.NullPointerException component argument pData

I've been searching all sources possible to find out where a chain of errors ending in "NullPointerException: component argument pData" comes from and have found nothing that can help solve my problem. My code runs but ends with a series of errors that occasionally freezes my computer when the program closes. The errors provide no reference to where it is originating in my program, and I've confirmed that it takes place after the final command in my program. I have no idea what to fix to end this error; I've narrowed down the flawed coding to a relatively small block, and to recreate the error, simply run the coding. I would GREATLY appreciate any help on this, as I have futilely spent countless attempting to fix it.

// creates the main block of code for this Test program

import java.awt.*;

import java.awt.image.*;

import java.awt.event.*;

import java.awt.geom.AffineTransform;

import java.util.ArrayList;

import javax.swing.*;

import java.util.Random;

import java.util.LinkedList;

import java.util.Iterator;

import java.awt.Graphics2D.*;

import java.io.*;

publicclass TestErrorimplements KeyListener

{

privatefinal DisplayMode POSSIBLE_MODES[] ={

new DisplayMode(800, 600, 32, 0),

new DisplayMode(800, 600, 24, 0),

new DisplayMode(800, 600, 16, 0),

new DisplayMode(640, 480, 32, 0),

new DisplayMode(640, 480, 24, 0),

new DisplayMode(640, 480, 16, 0)};

private ScreenManager screen;

publicboolean isRunning, testingFlag =false;

publicstaticvoid main(String[] args)throws IOException

{

TestError OOG =new TestError();

OOG.run();

}

//manages running the important methods of the program

publicvoid run()throws IOException

{

isRunning =true;

screen =new ScreenManager();

try{

DisplayMode displayMode =

screen.findFirstCompatibleMode(POSSIBLE_MODES);

screen.setFullScreen(displayMode);

Window window = screen.getFullScreenWindow();

window.addKeyListener(this);

animationLoop();}

finally{

screen.restoreScreen();

System.out.println("Test1");

}

}

public Image loadImage(String fileName)

{

returnnew ImageIcon(fileName).getImage();

}

publicvoid animationLoop()

{

long startTime = System.currentTimeMillis();

long currTime = startTime;

while (isRunning)

{

long elapsedTime = System.currentTimeMillis() - currTime;

currTime += elapsedTime;

//call the Graphics2d class, draw the image, then dispose Graphics

Graphics2D g = screen.getGraphics();

draw(g);

screen.update();

g.dispose();

//nap time

try{ Thread.sleep(20);}

catch (InterruptedException ex){}

}

}

publicvoid keyPressed (KeyEvent e)

{

int keyCode = e.getKeyCode();

if (keyCode == KeyEvent.VK_ESCAPE)

{

isRunning =false;

}

e.consume();

}

publicvoid keyTyped(KeyEvent e)

{

e.consume();

}

publicvoid keyReleased(KeyEvent e)

{

e.consume();

}

publicvoid draw(Graphics g)

{

int drawOffsetX, drawOffsetY;/*the offset will change where the pics are drawn

so that the screen scrolls with the char*/

drawOffsetX = 0;

drawOffsetY = 0;

//draws a simple background

g.setColor(Color.BLUE);

g.fillRect(0,0,800,800);

}

}

//manages initializing and displaying full screen graphics mode

class ScreenManager

{

private GraphicsDevice device;

//creates and instance of ScreenManager

public ScreenManager()

{

GraphicsEnvironment environment =

GraphicsEnvironment.getLocalGraphicsEnvironment();

device = environment.getDefaultScreenDevice();

}

//returns the list of compatible display modes for this system

public DisplayMode[] getCompatibleDisplayModes()

{

return device.getDisplayModes();

}

//finds the first compatible display mode

//returns null if no compatible modes are found

public DisplayMode findFirstCompatibleMode(DisplayMode modes[])

{

DisplayMode goodModes[] = device.getDisplayModes();

for (int i = 0; i < modes.length; i++)

{

for (int j = 0; j < goodModes.length; j++)

{

if(displayModesMatch(modes[i], goodModes[j]))

return modes[i];

}

}

returnnull;

}

//obtains the current display mode

public DisplayMode getCurrentDisplayMode()

{

return device.getDisplayMode();

}

/* Determines if two display modes match (if they have the same resolution,

* bit depth, and refresh rate. The bit depth is ignored if one mode has a

* bit depth of DispalyMode.BIT_DEPTH_MULTI; refresh rate is ignored if one

* is DisplayMode.REFRESH_RATE_UNKNOWN.*/

publicboolean displayModesMatch(DisplayMode mode1, DisplayMode mode2)

{

if (mode1.getWidth() != mode2.getWidth() ||

mode1.getHeight() != mode2.getHeight())

{

returnfalse;

}

if (mode1.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI &&

mode2.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI &&

mode1.getBitDepth() != mode2.getBitDepth())

{

returnfalse;

}

if (mode1.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN &&

mode2.getRefreshRate() != DisplayMode.REFRESH_RATE_UNKNOWN &&

mode1.getRefreshRate() != mode2.getRefreshRate())

{

returnfalse;

}

returntrue;

}

/* Changes the window to the full screen. If it has to be, the current

* display mode is used. The display uses a ButterStrategy with two

* buffers in order to allow the drawing to be more effective*/

publicvoid setFullScreen(DisplayMode displayMode)

{

JFrame frame =new JFrame();

frame.setUndecorated(true);

frame.setIgnoreRepaint(true);

frame.setResizable(false);

device.setFullScreenWindow(frame);

if (displayMode !=null && device.isDisplayChangeSupported())

{

try

{

device.setDisplayMode(displayMode);

}

catch(IllegalArgumentException ex){}

}

frame.createBufferStrategy(2);

}

/* Get graphics context for the display. The ScreenManager uses double

* buffering, so applications MUST call update() to show any graphics

* drawn... there is NO automatic repaint();

* The application must dispose of the graphics context*/

public Graphics2D getGraphics()

{

Window window = device.getFullScreenWindow();

if (window !=null)

{

BufferStrategy strategy = window.getBufferStrategy();

return (Graphics2D)strategy.getDrawGraphics();

}

else

{

returnnull;

}

}

//update method, which must be called (there is no auto repaint)

publicvoid update()

{

Window window = device.getFullScreenWindow();

if (window !=null)

{

BufferStrategy strategy = window.getBufferStrategy();

if (!strategy.contentsLost())

{

strategy.show();

}

}

//Sync the display on some problems, like Linux

Toolkit.getDefaultToolkit().sync();

}

//returns the window currently used in full screen mode

public Window getFullScreenWindow()

{

return device.getFullScreenWindow();

}

//returns width or height currently used in full screen mode

publicint getWidth()

{

Window window = device.getFullScreenWindow();

if (window !=null)

{

return window.getWidth();

}

else

{

return 0;

}

}

publicint getHeight()

{

Window window = device.getFullScreenWindow();

if (window !=null)

{

return window.getHeight();

}

else

{

return 0;

}

}

//restores the screen's display mode

publicvoid restoreScreen()

{

Window window = device.getFullScreenWindow();

if (window !=null)

{

window.dispose();

}

device.setFullScreenWindow(null);

}

//creates an image compatible with the current display

public BufferedImage createCompatibleImage(int w,int h,

int transparency)

{

Window window = device.getFullScreenWindow();

if (window !=null)

{

GraphicsConfiguration gc = window.getGraphicsConfiguration();

return gc.createCompatibleImage(w, h, transparency);

}

returnnull;

}

}

[16755 byte] By [MrShadow7a] at [2007-10-1 21:14:48]
# 1
Post a full representative stack trace.
paulcwa at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

Here's the stack trace. (Test1 is just a debugging tool I left in to show where the error is occuring in terms of the programs order of commands).

Test1

java.lang.NullPointerException: component argument pData

at sun.awt.windows.Win32BackBufferSurfaceData.initSurface(Native Method)

at sun.awt.windows.Win32BackBufferSurfaceData.createData(Win32BackBuffer

SurfaceData.java:49)

at sun.awt.windows.Win32BackBuffer.createHWData(Win32BackBuffer.java:28)

at sun.awt.windows.WVolatileImage.initAcceleratedBackground(WVolatileIma

ge.java:100)

at sun.awt.windows.Win32BackBuffer.displayChanged(Win32BackBuffer.java:3

5)

at sun.awt.SunDisplayChanger.notifyListeners(SunDisplayChanger.java:102)

at sun.awt.Win32GraphicsEnvironment.displayChanged(Win32GraphicsEnvironm

ent.java:98)

at sun.awt.windows.WToolkit$4.run(WToolkit.java:723)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh

read.java:197)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre

ad.java:150)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

Press any key to continue...

MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3
I forgot to mention, for anyone who tries to run program but hasn't yet read through it yet, you can close the program and see the error by pressing the Escape button.
MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4
You've truncated the stack trace. Can you print the whole thing, or at least until it starts showing your own code?
paulcwa at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 5
Sorry, but that is the entire print-out that appears in my DOS screen.
MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 6

Apparently, you have to press a key to continue. If you do that, maybe the rest of the stack trace will show up.

Also you can redirect the error messages to a file. (Well you can in a unix/linux environment; hopefully Microsoft **** will let you do so as well.) Like this:

java MyProgram 2> errorOutput.txt

Then hopefully it'll show the full stack trace.

paulcwa at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 7

Ok, I'm working on it right now. I've been running it from a Java work environment which allowed me to compile and run it without using the command line (which is why the "Press Any Key to Continue..." appears. Once a button is pressed, it closes out the temporarily DOS screen). I'll post a copy of what you requested as soon as I get it working.

MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 8
I find in cases like this it's sometimes easiest to just fall back to standard SDK components. Invoking java from the command line maybe a bit clunkier but it makes it easier sometimes to do things like get stack traces.
paulcwa at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 9

I'm really sorry about how long it took to get the info you wanted.I was just making a really stupid mistake. Here's what it shows when I run it from the command line:

Microsoft Windows XP [Version 5.1.2600]

(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Owner>cd ../..

C:\>cd JavaTest

C:\JavaTest>java TestError > errorOutput.txt

java.lang.NullPointerException: component argument pData

at sun.awt.windows.Win32BackBufferSurfaceData.initSurface(Native Method)

at sun.awt.windows.Win32BackBufferSurfaceData.createData(Unknown Source)

at sun.awt.windows.Win32BackBuffer.createHWData(Unknown Source)

at sun.awt.windows.WVolatileImage.initAcceleratedBackground(Unknown Sour

ce)

at sun.awt.windows.Win32BackBuffer.displayChanged(Unknown Source)

at sun.awt.SunDisplayChanger.notifyListeners(Unknown Source)

at sun.awt.Win32GraphicsEnvironment.displayChanged(Unknown Source)

at sun.awt.windows.WToolkit$4.run(Unknown Source)

at java.awt.event.InvocationEvent.dispatch(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

C:\JavaTest>

The program it prints to only ends up printing out "Test1". I'd also like to thank you for the java code > filename tip. I didn't realize you could do that with Java and it sounds like it's a useful thing to know.

MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 10

OK, after all that I'm not sure how helpful I can be. I was expecting the stack trace to include one of your classes.

But it occurs to me, that in your restoreScreen method, you call window.dispose() before you turn off full screen mode. Are you sure it shouldn't be the other way around?

paulcwa at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 11

Regardless of whether you are able to resolve the error or not, thank you for the help. You spent a lot of time on a thread where I wasn't really able to give you all the information you wanted. I tried switching around those two threads and got this:

Test1

An unexpected exception has been detected in native code outside the VM.

Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D069916

Function=Java_sun_print_Win32PrintJob_printRawData+0x4F26

Library=C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\bin\awt.dll

Current Java thread:

at sun.java2d.DefaultDisposerRecord.invokeNativeDispose(Native Method)

at sun.java2d.DefaultDisposerRecord.dispose(DefaultDisposerRecord.java:2

4)

at sun.java2d.Disposer.run(Disposer.java:99)

at java.lang.Thread.run(Thread.java:536)

Dynamic libraries:

0x00400000 - 0x00406000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\bin\

java.exe

0x7C900000 - 0x7C9B0000 C:\WINDOWS\system32\ntdll.dll

0x7C800000 - 0x7C8F4000 C:\WINDOWS\system32\kernel32.dll

0x77DD0000 - 0x77E6B000 C:\WINDOWS\system32\ADVAPI32.dll

0x77E70000 - 0x77F01000 C:\WINDOWS\system32\RPCRT4.dll

0x77C10000 - 0x77C68000 C:\WINDOWS\system32\MSVCRT.dll

0x6D340000 - 0x6D46A000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\client\jvm.dll

0x77D40000 - 0x77DD0000 C:\WINDOWS\system32\USER32.dll

0x77F10000 - 0x77F56000 C:\WINDOWS\system32\GDI32.dll

0x76B40000 - 0x76B6D000 C:\WINDOWS\system32\WINMM.dll

0x6D1E0000 - 0x6D1E7000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\hpi.dll

0x6D310000 - 0x6D31E000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\verify.dll

0x6D220000 - 0x6D239000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\java.dll

0x6D330000 - 0x6D33D000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\zip.dll

0x6D000000 - 0x6D105000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\awt.dll

0x73000000 - 0x73026000 C:\WINDOWS\system32\WINSPOOL.DRV

0x76390000 - 0x763AD000 C:\WINDOWS\system32\IMM32.dll

0x774E0000 - 0x7761D000 C:\WINDOWS\system32\ole32.dll

0x5AD70000 - 0x5ADA8000 C:\WINDOWS\system32\uxtheme.dll

0x6D190000 - 0x6D1E0000 C:\Program Files\s1studio_jdk\j2sdk1.4.1_02\jre\

bin\fontmanager.dll

0x73760000 - 0x737A9000 C:\WINDOWS\system32\ddraw.dll

0x73BC0000 - 0x73BC6000 C:\WINDOWS\system32\DCIMAN32.dll

0x73940000 - 0x73A10000 C:\WINDOWS\system32\D3DIM700.DLL

0x74720000 - 0x7476B000 C:\WINDOWS\system32\MSCTF.dll

0x605D0000 - 0x605D9000 C:\WINDOWS\system32\mslbui.dll

0x77120000 - 0x771AC000 C:\WINDOWS\system32\OLEAUT32.DLL

0x76C90000 - 0x76CB8000 C:\WINDOWS\system32\imagehlp.dll

0x59A60000 - 0x59B01000 C:\WINDOWS\system32\DBGHELP.dll

0x77C00000 - 0x77C08000 C:\WINDOWS\system32\VERSION.dll

0x76BF0000 - 0x76BFB000 C:\WINDOWS\system32\PSAPI.DLL

Local Time = Thu Aug 18 20:57:20 2005

Elapsed Time = 3

#

# The exception above was detected in native code outside the VM

#

# Java VM: Java HotSpot(TM) Client VM (1.4.1_02-b06 mixed mode)

#

# An error report file has been saved as hs_err_pid2868.log.

# Please refer to the file for further information.

#

Press any key to continue...

This might be better, as I don't seem to get a stalling in the computer at the end of the program Either way, the program still runs luckily, since the error occurs after everything has executed; however, the original way I had it occasionaly froze my computer.

I'm embarrassed to admit it, but the ScreenManager class isn't my own class. I understand about half of it, but I'm not very well-versed in hardware related program in Java, so I don't know much about debugging these sorts of things. The most annoying thing is that I've used this before without problems, and without a link to somewhere in my program, I'm not really sure how to debug it either.

MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 12

I googled for this error and found a few hits...it sounds like it's a known bug.

It may be worth switching to the latest JVM, if you're not already running it, to see if it's been fixed.

Also you can try posting on the Games forum. The people who hang out there are more likely to be familiar with the issues surrounding full-screen exclusive mode.

Sorry I couldn't be of more help.

paulcwa at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 13
Ok, thank you, you've been extremely helpful.
MrShadow7a at 2007-7-13 3:11:18 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...