aspose file tools*
The moose likes Game Development and the fly likes nullPointerException found regarding Window Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "nullPointerException found regarding Window" Watch "nullPointerException found regarding Window" New topic
Author

nullPointerException found regarding Window

Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
I am trying to get a fullScreen window created. After going through a few tutorials on it I narrowed my problem down to this error:




here is my driver file:


here is my driven file:


After reading up on Windows and how to build them, It mentioned I needed to associate the Window with a Frame as its owner. It didnt supply an actual example of this in practice, so I just gave it my best shot.

Window w = new Window(JFrame window);

Obviously this didnt work, it refered to JFrame as a variable, should this be where the JFrame's variable is placed?

It also mentioned a whole slew of other errors indicating this is not correct in the slightest.



So needless to say, I am not sure where to go from here.

Thanks a lot for the help
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Well, I'm no expert, but I have seem my share of null-pointer exceptions, so I'll give it a go.

First of all, I have a problem relating the line numbers specified in the error messages to the line numbers in the code you have pasted. If you can clarify this, then I'll take a look and see if I can spot the problem.
Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
Sorry about that, I deleted all my comments I added to help remember what everything does. Here is as it was before I deleted the comments



# Exception in thread "main" java.lang.NullPointerException
# at Screen_Sub.restoreScreen(Screen_Sub.java:54)
# at Screen_Main.run(Screen_Main.java:44)
# at Screen_Main.main(Screen_Main.java:15)




Screen_Main.java



Screen_Sub.java

Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Well, for starters, it seems to me that the error means that at the time that Screen_Sub.restoreScreen() gets called, your GraphicsDevice vc has not been instantiated, or has been set to null. That seems obvious. What does not seem obvious is why? I didn't do a carefull trace, but there is one or two things you can look at.

in your Screen_Sub constructor, you have the line vc = env.getDefaultScreenDevice(); I would take a look at this statement and ask whether or not it is possible that the getDefaultScreenDevice() method is returning null. If you find that this is the case, then you have to ask yourself why, and that is not something I can tell you about.
Ben Hultin
Ranch Hand

Joined: Aug 17, 2009
Posts: 135
Thanks a lot for the help, I took a look around read a quick tutorial on checking methods to be null or not. I tried two different methods, but I wasnt able to get a reponse either way about if they are null or not. Here are the two methods I checked.





I put both of these tests at the bottom of the constructor. Suggestions on how I can check if they null or not?
Fred Hamilton
Ranch Hand

Joined: May 13, 2009
Posts: 679
Ben Hultin wrote: ...Suggestions on how I can check if they null or not?


That's the easy part. You want to know if the object vc is null., So you use a strategically placed if( vc == null ) condition along with some informational message. The end of the Screen_Sub constructor is a good place to start.
 
 
subject: nullPointerException found regarding Window