• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

display image selected by Jfilechooser on the content pane of the frame

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is my code. I want to display an image chosen by Jfilechooser on the content pane of the frame. Since i have designed frame in different class, i am enable to add image panel to the cintent pane. i have tried below code, but it is showing null pointer exception. Can anybody help me to know where is the error in the code & what should i do to make its working correct?
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

khushi garg wrote:Can anybody help me to know where is the error in the code & what should i do to make its working correct?


The NPE tells you exactly in which file and on which line in that file it occurs. You should start there.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cross posted
http://www.java-forums.org/awt-swing/30768-how-display-image-selected-jfilechooser.html
 
Marshal
Posts: 80288
433
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Make sure to tell everybody when you cross-post.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
post up the log of error, maybe we can see where you erring. But you have to know than NullPointerException points to an object that is being loaded without receiving a value.
 
khushi garg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
error that is occuring after selecting file from JFilechooser


c:\javac ImageEditor.java

c:\java ImageEditor
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at OpenDialog.<init>(ImageEditor.java:26)
at MenuHandler.actionPerformed(ImageEditor.java:163)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:20
13)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2336)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:405)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:260
)
at javax.swing.AbstractButton.doClick(AbstractButton.java:375)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1
238)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMen
uItemUI.java:1282)
at java.awt.Component.processMouseEvent(Component.java:6100)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3288)
at java.awt.Component.processEvent(Component.java:5865)
at java.awt.Container.processEvent(Container.java:2099)
at java.awt.Component.dispatchEventImpl(Component.java:4461)
at java.awt.Container.dispatchEventImpl(Container.java:2157)
at java.awt.Component.dispatchEvent(Component.java:4287)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4455
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4119)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4049)
at java.awt.Container.dispatchEventImpl(Container.java:2143)
at java.awt.Window.dispatchEventImpl(Window.java:2555)
at java.awt.Component.dispatchEvent(Component.java:4287)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:605)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:276)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:191)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)

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

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


 
khushi garg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my complete code is:

 
Rob Spoor
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why post the entire code when the exception clearly shows where it is? It's located on line 26, in the OpenDialog constructor. My guess it's this line:
After all, where have you initialized frame? You haven't!

I don't see the purpose of the entire class though. It extends Component yet you never use it as a component. It's never added to any container. However, it isn't necessary either. All the entire class ever does is show the open dialog and process its selected file. You can better just copy the code in the constructor to the event handler, and drop the entire class completely (and SaveDialog as well):
 
khushi garg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made some changes in the code but still unable to make out how to add label to the frame. Please help me
 
Right! We're on it! Let's get to work tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic