Using XPathAPI.selectSingleNode directly from an exe file

D

dushkin

Hi All!
I am using Xalan API on my program.

I found out that the function XPathAPI.selectSingleNode worked
perfectly when I used it when running debug mode on my JBuilder.
But when I wanted to try the produced exe file, outside the development
envirionment, this function crshed! It is not the application crashed,
but the fuction simply didn't work. Maybe it throwed an exeption, but
it didn't show the meesage which I put right after the line.

Can you advice please?...

Thanks!
 
A

Andrew Thompson

dushkin wrote:
....
I am using Xalan API on my program.

I found out that the function XPathAPI.selectSingleNode worked
perfectly when I used it when running debug mode on my JBuilder.
But when I wanted to try the produced exe file,

An 'exe'? Do you mean packaged Jar executables,
or a file that ends with '.exe'?
...outside the development
envirionment, this function crshed! It is not the application crashed,
but the fuction simply didn't work. Maybe it throwed an exeption, but
it didn't show the meesage which I put right after the line.

Do you have a 'catch'? Does it printStackTrace()?
Can you advice please?...

Make sure you do and it does.

That should allow you to come back to us with a
more definitive failure description than 'the function
simply didn't work'.

Andrew T.
 
D

dushkin

Thank you Allan for you response.

I must put the function under try/catch block otherwise the program
won't be built.

This is the code segment:

******************************************
Node nd = null;
try {

JOptionPane.showMessageDialog(m_wFrame, "1", "1",
JOptionPane.INFORMATION_MESSAGE);

xmlMapNode = XPathAPI.selectSingleNode(doc,
nd.getXPath());

JOptionPane.showMessageDialog(m_wFrame, "2", "2",
JOptionPane.INFORMATION_MESSAGE);

} catch (TransformerException ex) {

JOptionPane.showMessageDialog(m_wFrame,
ex.getMessage(), "Debug", JOptionPane.INFORMATION_MESSAGE);

ex.printStackTrace();

return;
}
********************************************

When I run the code from the JBuilder by using "Debug" mode, there is
no problem.
But when I run it as a stand alone exe, only "1" message appears! o
other message "2" nor getMessage() appears.

Thanks.
 
A

Andrew Thompson

dushkin said:
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.
 
D

dushkin

Hi Andrew,

nd is of course not null. Otherwise it would have be falling also
inside the debugger too.
It was my mistake. I just tried not to confuse you with my
variables...

I added the throwable catch, and it really caught the exception!
But, I couldn't find any interesting information there.

(Sorry I still didn't study the SSCCE issue - I promise I will, but no
time now... :-( )

So , This is the updated and non modified code and the result:

--------------------------------------------------
Node xmlMapNode = null;
try {
Document doc = xTreeScm.getDocument();
String sXPath = mapMutNode.getXPath();

JOptionPane.showMessageDialog(m_wFrame, "Doc
element name: " + doc.getDocumentElement().getNodeName(), "Debug",
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(m_wFrame, "xPath: " +
sXPath, "Debug", JOptionPane.INFORMATION_MESSAGE);
xmlMapNode = XPathAPI.selectSingleNode(doc,
sXPath);
JOptionPane.showMessageDialog(m_wFrame, "1", "1",
JOptionPane.INFORMATION_MESSAGE);

} catch (TransformerException ex) {
JOptionPane.showMessageDialog(m_wFrame,
ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
return;
} catch (Throwable t) {
//what *else* could be failing here?!?
JOptionPane.showMessageDialog(m_wFrame,
"Throwable Message: " + t.getMessage(),
"Error", JOptionPane.ERROR_MESSAGE);
t.printStackTrace();
}
----------------------------------------------------

The result was : org/apache/xpath/XPathAPI...


No great news here I suspect...

I thank you so much for your time. Any more ideas?...
 
D

dushkin

Also, t.getCause() returned null...

Couldn't the whole problem be related to libraries versions for
example?...
 
D

dushkin

Even more info:

t.toString(): java.lang.NoClassDefFoundError:
org/apache/xpath/XPathAPI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top