This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
    Bookmark Topic Watch Topic
  • New Topic

why i'm getting nullpointer exception here?  RSS feed

 
vishnu vardhan brundavanam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
hi...everyone....
I created an applet which contains a manubar .In that menubar only one manuitem " load file..."(menu item) is there. Which is used to browse the a file which contains a number of values to draw the graph. By that values i want to draw a line graph .
my aim is that when ever i browse a new file , take the values form that and to draw new graph base on the old scale.(if i browsed two files ,then the graph should contain two line graphs ) ...
here is the calling one...

But,i'm getting null pointer exception in this code....why?

here is the code....


The output is given bellow...
please resolve this...
please help me...
thank you...



itemselected...
the path of the file is :C:\data\data.txt
java.lang.NullPointerException
at MenuImplimentation.actionPerformed(MenuImplimentation.java:104)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

output3.jpg
[Thumbnail for output3.jpg]
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Report post to moderator
In which line of code does the exception occur? Which object is null?
 
vishnu vardhan brundavanam
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
in line number 104,110& 112
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
  • Report post to moderator
You shouldn't be doing painting in an action handler. You need a paint (or paintComponent) method that is invoked by you calling repaint(), as has been suggested to you elsewhere.

Start by working through http://download.oracle.com/javase/tutorial/uiswing/painting/.

Also note that mixing AWT and Swing components is a bad idea, as was pointed out as well.
 
Udara Amarasinghe
Ranch Hand
Posts: 109
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Report post to moderator
I agree with Lester Burnham the getGraphics() method returns null when the component is not displaying on the screen it return actual graphics object only when the component is displaying on the screen (read getGraphics() method ditails).
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!