• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null Pointer Exception in a GUI application (2)

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:


 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Haani Naz
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ernest Friedman-Hill wrote:Look at these three lines very carefully:



Notice anything wrong?




gosh now i just feel stupid lol

thanks man.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Saloon Keeper
Posts: 15490
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Haani Naz,
Your post was moved to a new topic.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ...
 
Liar, liar, pants on fire! refreshing plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic