I have a problem. I wanted to add a stopwatch display to my app. I used this page as a reference. I downloaded and added necessary commons-scxml-0.9.jar libraries (with source code). There are no errors in Eclipse but when I debug it, in this class constructor of super-class (AbstractStateMachine) is called with this command:
super(StopWatch.class.getClassLoader().getResource("org/apache/commons/scxml/env/stopwatch.xml"));
but Super-class constructor doesn't get any attribute. It expects final URL scxmlDocument but only null appears.
I know how stopwatch.xml looks but where should I place it, and how do I create final URL scxmlDocument from it?
I tried everything but nothing worked.
Thank you all !!
This is stopwatch.xml, if i add it eclipse reports errors because of id attribute:
`<?xml version="1.0" ?>
<transition event="watch.start" target="running" />
</state>
<state id="running">
<transition event="watch.split" target="paused" />
<transition event="watch.stop" target="stopped" />
</state>
<state id="paused">
<transition event="watch.unsplit" target="running" />
<transition event="watch.stop" target="stopped" />
</state>
<state id="stopped">
<transition event="watch.reset" target="reset" />
</state>
`
Your code looks fine. If you're getting an exception at run time, you should have included it with your question. The XML also looks fine, except that you have excluded the first few lines and the last line (was this intentional or is your XML really missing these lines?). This is my XML:
As for where to put the XML file, typically you would put it in the SRC directory. When Eclipse does the build, it won't know what to do with the XML file and so, its default behavior, is to copy it to the BIN directory where the compiled code goes. You may need to do a
Project > Clean...
to get this to happen. This is where the run time environment typically expects to find resources like this.Here's a really good trick: If you're doing your development on any version of Windows you can go to Microsoft's incredibly good Sysinternals site (http://technet.microsoft.com/en-US/sysinternals). Here you can find the wonderful Process Monitor utility. Download, install and run this free utility. From within the utility, create a Process Monitor Filter:
Path | contains | stopwatch.xml
Make sure this filter is enabled and all the other (predefined) filters are disabled.Then run your compiled stopwatch program. The utility will display EVERY location the application (and all of the class loaders contained therein) looks for
stopwatch.xml
.You can then move/copy/whatever the file to make sure it's in a place the application looks to locate the file. This utility is especially handy for similar "I can't find the resource" issues that occur when writing J2EE apps (e.g. Tomcat, Websphere, etc.).
And finally, while you didn't mention anything about dependent jar files, make sure these are on the classpath: