• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
khushi garg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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?
 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cross posted
http://www.java-forums.org/awt-swing/30768-how-display-image-selected-jfilechooser.html
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Make sure to tell everybody when you cross-post.
 
Eduardo Ewerton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
my complete code is:

 
Rob Spoor
Sheriff
Pie
Posts: 20512
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic