wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Null Pointer Exception in a GUI application (2) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Null Pointer Exception in a GUI application (2)" Watch "Null Pointer Exception in a GUI application (2)" New topic
Author

Null Pointer Exception in a GUI application (2)

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Haani Naz wrote:This fails to work - i get run time errors.

Please tell us exactly what those errors are, that would make it a lot easier to help you find the cause.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Haani Naz
Greenhorn

Joined: May 30, 2010
Posts: 23
Jesper de Jong wrote:
Haani Naz wrote:This fails to work - i get run time errors.

Please tell us exactly what those errors are, that would make it a lot easier to help you find the cause.


Sure. this is what i get:


Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Look at these three lines very carefully:



Notice anything wrong? Hint: note that the stack trace tells you the error is on line 47 of FirstGUI.java


which is this line:


Note that this is an excellent example of why you should start a new thread when you have a new question -- I'm afraid this problem has nothing to do with the topic of this thread.


[Jess in Action][AskingGoodQuestions]
Haani Naz
Greenhorn

Joined: May 30, 2010
Posts: 23
Ernest Friedman-Hill wrote:Look at these three lines very carefully:



Notice anything wrong?



gosh now i just feel stupid lol

thanks man.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

Rob Spoor wrote:Why I still do it then? Habit I guess. Laziness as well probably.


I think it's a conceptual thing. If you think of the frame being the application (which for many single-window applications it's perfectly understandable), then extending JFrame makes sense. The application IS-A frame.

I'm not saying I think it's brilliant design, although I also do it myself occasionally. But I don't think it necessarily leads to bad code. One place it really falls down is if you might feasibly want to convert the application to a different framework.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3605
    
  14

An application is not a JFrame and it never will be. In my mind, the JFrame models the outermost rim of the application (like the frame of a picture), and only includes the system menu, the state buttons; it has a dimension and it holds the various panels the application may make use of. It also does all of this just perfectly, without any ambiguity, so there's never any reason to extend it, unless you want to add new system buttons, or functionality, like being able to pin it to the foreground or something like that (which at this point I'm not entirely convinced you can't do in another way).

The same application may work just fine in a console, in a dialogue, in an applet, etc. By letting it extend a JFrame, you're also making that part of your application's API; effectively binding your application to a JFrame forever. Of course it doesn't matter much if you make the main class package private, but I don't see why you wouldn't take 2 extra minutes to do it properly.

People usually seem to treat their main class differently than they would other, better designed classes that are deeper inside the application. They think: "this class is only important to this particular application, or this particular version of it, so I can just quickly throw something together".
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Ernest Friedman-Hill wrote: . . . start a new thread when you have a new question -- I'm afraid this problem has nothing to do with the topic of this thread.
Agree. Splitting thread.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
Haani Naz,
Your post was moved to a new topic.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38107
    
  22
I earlier wrote:Haani Naz,
Your post was moved to a new topic.
That was an automated post. At the end of that link, you will come back to this thread, because I made a mistake moving that post.

You can go to that link, back here, other there, back here, over there, back here ...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer Exception in a GUI application (2)
 
Similar Threads
Regarding Base64 emails
el-ignored query
regarding JTable
Struts2.0+Ejb3.0 Vs Spring+Hibernate
using jdbc thin driver of oracle 10XE