Re: JDOM and Android
Rolf Lear <[email protected]> Tue, 17 Apr 2012 00:51:59 -0400
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
I have been down that road, and it does not work.... Because the file URL's are still not readable.... here's a test trace... Note how the failure is buried in a 'caused by' where the important lines are: Caused by: java.io.FileNotFoundException: /android_asset/xsdcomplex/multi_main.xsd: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:406) at java.io.FileInputStream.<init>(FileInputStream.java:78) at libcore.net.url.FileURLConnection.connect(FileURLConnection.java:82) at libcore.net.url.FileURLConnection.getInputStream(FileURLConnection.java:181) at java.net.URL.openStream(URL.java:462) at org.jdom2.input.sax.XMLReaderXSDFactory.getSchemaFromURL(XMLReaderXSDFactory.java:195) ... 15 more org.jdom2.JDOMException: Unable to read Schema URL file:///android_asset/xsdcomplex/multi_main.xsd at org.jdom2.input.sax.XMLReaderXSDFactory.getSchemaFromURL(XMLReaderXSDFactory.java:197) at org.jdom2.input.sax.XMLReaderXSDFactory.<init>(XMLReaderXSDFactory.java:272) at org.jdom2.test.cases.input.sax.TestXMLReaderXSDFactory.testXMLReaderXSDFactoryFileArray(TestXMLReaderXSDFactory.java:80) at org.jdom2.test.cases.input.sax.TestXMLReaderXSDFactoryTT.testXMLReaderXSDFactoryFileArray(TestXMLReaderXSDFactoryTT.java:28) at java.lang.reflect.Method.invokeNative(Native Method) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:545) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551) Caused by: java.io.FileNotFoundException: /android_asset/xsdcomplex/multi_main.xsd: open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:406) at java.io.FileInputStream.<init>(FileInputStream.java:78) at libcore.net.url.FileURLConnection.connect(FileURLConnection.java:82) at libcore.net.url.FileURLConnection.getInputStream(FileURLConnection.java:181) at java.net.URL.openStream(URL.java:462) at org.jdom2.input.sax.XMLReaderXSDFactory.getSchemaFromURL(XMLReaderXSDFactory.java:195) ... 15 more Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110) at libcore.io.IoBridge.open(IoBridge.java:390) ... 20 more On 17/04/2012 12:00 AM, Joe Bowbeer wrote: > You'll need to put the data in assets > > http://stackoverflow.com/questions/4820816/how-to-get-uri-from-an-asset-file > > http://stackoverflow.com/questions/4789325/android-path-to-asset-txt-file > > and use getResources().getAssets().open() > > Or you could put the data in res/raw and use > getResources().openRawResource() > > .. but res/raw does not support a nested file structure. > > Or maybe you could do something crazy with a custom class loader: > > http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html > > > --Joe > > > On Mon, Apr 16, 2012 at 8:08 PM, Rolf Lear <[email protected] > <mailto:[email protected]>> wrote: > > Hi all. > > I am having some limited success with the Android testing. I have > run in to an issue through which could really use some input from > experienced Android developers. > > Are there any on JDOM-interest with some time to spare? > > My issue right now is that the JUnit tests are mostly passing, but a > number of them rely on using > ClassLoader.getSystemResource(__"path/to/file.xml") to load > resources as a URL. > > It is improtant to keep it as a URL because many of these tests rely > on internal DTD's and XSD's, which, in turn mean that when they are > processed the input file's URL will be used as a base for a relative > location of the DTD/XSD. > > In other words, I need to keep access to these files as a URL.... > > But, ClassLoader.getSystemResource(__...) is returning null on Android. > > I think it is related to > http://code.google.com/p/__android/issues/detail?id=10076 > <http://code.google.com/p/android/issues/detail?id=10076> > > But, I can't find a good way to work around the issue.... > > So, If there's some experienced Android developer who can shed some > light in to this particular dark place, I would appreciate it. > > For the record, I have a full test-suite available for any Android > developers who happen to use eclipse. It fully compiled, loads, and > I am running a 'Test' Project on a 4.0.3 emulator. > > I can, in theory, help you bootstrap the environment in your eclipse > pretty easily... if needed. > > Rolf > _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/[email protected]