Re: Using XPathAPI.selectSingleNode directly from an exe file
dushkin wrote:
Thank you Allan for you response.
Noted your correction in next post. No biggie.
(Though, tip - that's one good reason not to put
names or personal messages in replies!)
I must put the function under try/catch block otherwise the program
won't be built.
OK - got you. But there are 'checked' and 'unchecked'
exceptions...*
This is the code segment:
Uggh.. have I expressed yet today, just how much I
dislike code snippets? Probably not, but for future
reference, preparing an SSCCE will probably help you
to solve most problems yourself, and if not, it will
reult in a short, self contained code that disdplay
the problem. More details here..
<http://www.physci.org/codes/sscce/>
But....
******************************************
Node nd = null;
try {
JOptionPane.showMessageDialog(m_wFrame, "1", "1",
JOptionPane.INFORMATION_MESSAGE);
xmlMapNode = XPathAPI.selectSingleNode(doc,
nd.getXPath());
...node 'nd' should be null here, so this will throw an *un*checked
exception, specifically a NullPointerException, that will ..
JOptionPane.showMessageDialog(m_wFrame, "2", "2",
JOptionPane.INFORMATION_MESSAGE);
} catch (TransformerException ex) {
Not be caught be this catch..
You might add..
JOptionPane.showMessageDialog(m_wFrame,
ex.getMessage(), "Debug", JOptionPane.INFORMATION_MESSAGE);
ex.printStackTrace();
return;
} catch(NullPointerException npe)
npe.pintStackTrace();
}
...but instead I would recommend, for *any* code that is broken,
adding a final...
} catch (Throwable t) {
//what *else* could be failing here?!?
t.printStackTrace();
}
********************************************
When I run the code from the JBuilder by using "Debug" mode, there is
no problem.
That is odd. I do not understand how that code could
work in 'debug', or any other, mode.
But when I run it as a stand alone exe,
You still have not mentioned if this exe is a '.exe'.
* Oh, yes. A NullPointerException is an unchecked exception,
which means the compiler does not force you to wrap the code
in a try/catch, but instead lets the programmer 'take their
chances', and deal with the consequences.
HTH
Andrew T.