Meaningless Drivel is fun!*
The moose likes Other JSE/JEE APIs and the fly likes Desktop.Action.EMAIL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Desktop.Action.EMAIL" Watch "Desktop.Action.EMAIL" New topic
Author

Desktop.Action.EMAIL

Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125


hi i have this code that call the main default software for mail, but i get a nullpointerexception error, usually is an error made by a null value on the URI, but is not empty, and i get same error even just calling d.mail()

i checked isSupported and isDesktopSupported and they are true
i simply call that funct in a button with the code
Desktop d = null;
d.getDesktop();
onLaunchMail();

this is the error

java.lang.NullPointerException
at desktopapplication1.TbEvent.onLaunchMail(TbEvent.java:253)
at desktopapplication1.TbEvent.actionPerformed(TbEvent.java:201)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6263)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6028)
at java.awt.Container.processEvent(Container.java:2041)
at java.awt.Component.dispatchEventImpl(Component.java:4630)
at java.awt.Container.dispatchEventImpl(Container.java:2099)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4574)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
at java.awt.Container.dispatchEventImpl(Container.java:2085)
at java.awt.Window.dispatchEventImpl(Window.java:2475)
at java.awt.Component.dispatchEvent(Component.java:4460)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337

Desktop d = null;
d.getDesktop();

Is this actual code? If "d" is null then you can't invoke a method on it; you'll get a NullPointerException. I think you're missing a line of code that assigns something to "d".
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Lester Burnham wrote:

Desktop d = null;
d.getDesktop();

Is this actual code? If "d" is null then you can't invoke a method on it; you'll get a NullPointerException. I think you're missing a line of code that assigns something to "d".

is not enough the getDesktop() ?
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Whatever the "getDesktop" method returns can't be used, since it's not assigned to anything. I think you meant to write

Desktop d = Desktop.getDesktop();
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
just corrected as you suggested, but it give the same error

on the line d.mail(uri)

i tried with removing uri but the same
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19672
    
  18

How and where are you now initializing d?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
The variable "d" in the actionPerformed method hides the instance variable of the same name, which consequently is never assigned anything. If you write "d = Desktop.getDesktop();" in actionPerformed, then all should work.
Antony Amicone
Ranch Hand

Joined: Mar 11, 2006
Posts: 125
it works!!

really ty all
 
wood burning stoves
 
subject: Desktop.Action.EMAIL