• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JFrame application HELP Needed ! ! ! (STILL NEED HELP)

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranch Hands:

There is a lot of code here. Do not let it throw you. Most of it is here to avoid having to repost it if someone has a question
The problem lies within the statement followed by this comment (I think)
// # # # PROBLEM # # # in class MYFrame.
All code compiles clean.
OBJECT: Illustrate inheritance exercise which will have 15 random shapes drawn on a JFrame.
PROBLEM: When I execute the Driver the JFrame is BLANK. If you drag the frame the program executes as expected but it produces the following list of runtime errors:
java.lang.NullPointerException
at MyFrame.paint(MyFrame.java:55)
at sun.awt.RepaintArea.paint(RepaintArea.java:177)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
at java.awt.Component.dispatchEventImpl(Component.java:3699)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Window.dispatchEventImpl(Window.java:1590)
at java.awt.Component.dispatchEvent(Component.java:3480)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.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)
Thanks for your expert help.
75gator


[ April 13, 2004: Message edited by: Douglas Braxton ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum, where they love to get all messy with this GUI stuff...
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Douglas.
Just make setVisible(true) the last opeation in MyFrame constructor or remove it from constructor at all and put to the main function like this:
public static void main (String[ ] arg)
{
MyFrame mFrame = new MyFrame();
mFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
mFrame.setVisible(true);
//System.exit(0);
}// terminate main
}// end of MyShapesDriver
Like it id now, your program tries to draw shapes before you create them and you're getting the NullPointerException.
Good luck.
Polina
 
Douglas Braxton
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. Problem solved!
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic