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