| Issue 27: | getResourceAsStream() path fails on Android | |
| 2 people starred this issue and may be notified of changes. | Back to list |
What steps will reproduce the problem? 1. Convert this app for android http://www.qcontinuum.org/compass/ 2. Run it, choose location, and press ok. What is the expected output? What do you see instead? An exception happens. V/MicroEmulator(17124): error V/MicroEmulator(17124): V/MicroEmulator(17124): java.io.FileNotFoundException: TimeZone.dat V/MicroEmulator(17124): at android.content.res.AssetManager.openAsset(Native Method) V/MicroEmulator(17124): at android.content.res.AssetManager.open(AssetManager.java:301) V/MicroEmulator(17124): at android.content.res.AssetManager.open(AssetManager.java:275) V/MicroEmulator(17124): at org.microemu.android.MicroEmulatorActivity$1.getResourceAsStream(MicroEmulatorActivity.java:127) V/MicroEmulator(17124): at org.microemu.app.Common.getResourceAsStream(Common.java:179) V/MicroEmulator(17124): at org.microemu.MIDletBridge.getResourceAsStream(MIDletBridge.java:132) V/MicroEmulator(17124): at org.qcontinuum.compass.TimeZone.getZones(Unknown Source) V/MicroEmulator(17124): at org.qcontinuum.compass.LocationTimeZone.<init>(Unknown Source) V/MicroEmulator(17124): at org.qcontinuum.compass.LocationMap.b(Unknown Source) V/MicroEmulator(17124): at org.qcontinuum.compass.LocationMap.commandAction(Unknown Source) V/MicroEmulator(17124): at javax.microedition.lcdui.Display$DisplayAccessor$1.run(Display.java:209) V/MicroEmulator(17124): at org.microemu.device.ui.EventDispatcher$RunnableEvent.run(EventDispatcher.java:246) V/MicroEmulator(17124): at org.microemu.device.ui.EventDispatcher.post(EventDispatcher.java:164) V/MicroEmulator(17124): at org.microemu.device.ui.EventDispatcher.run(EventDispatcher.java:99) V/MicroEmulator(17124): at java.lang.Thread.run(Thread.java:1096) What version of the product are you using? On what operating system? Trunk and r2211. Please provide any additional information below. I think it is because midlet was calling getResourceAsStream() with a relative path, which means relative to the class path. When calling android's AssetManager.open() we are discarding the path, then the problem.
Jan 15, 2010
Project Member
#1
bar...@gmail.com
Jan 15, 2010
Btw, it works with the applet version of microemu: http://www.latinsud.com/pub/jCompass/ It is only Android version that fails. 1. From source code of the application: org/qcontinuum/compass/TimeZone.java: InputStream inputStream = obj.getClass().getResourceAsStream("TimeZone.dat"); Please note that it is a relative path. Imho almost nobody uses relative paths, then the problem not being noticed before. 2. File was originally located in JAR: org/qcontinuum/compass/TimeZone.dat File path in APK: assets/org/qcontinuum/compass/TimeZone.dat My conclusion is: If "org/qcontinuum/compass/TimeZone.class" wants "TimeZone.dat", then we should look for "org/qcontinuum/compass/TimeZone.dat" I tried reading the JAVA API doc to find out what's the correct behaviour, but i coulndn't understand it fully. Btw, i did a dirty patch to prove my idea. In MicroEmulatorActivity.java:getResourceAsStream(String name) i replaced: return MicroEmulatorActivity.this.getAssets().open(name); with return MicroEmulatorActivity.this.getAssets().open("org/qcontinuum/compass/"+name); This patch trick worked, but i know it is not a general solution. It would require retrieveing the path of the calling class, but i currently don't know how to do it, sorry (maybe something in MIDletBridge.java?).
Jan 16, 2010
(No comment was entered for this change.)
Status:
Accepted
Jan 18, 2010
(No comment was entered for this change.)
Labels:
Milestone-3.0
Mar 26, 2010
Fix commited to trunk
Status:
Fixed
|