nonethespinosa / microemu

Automatically exported from code.google.com/p/microemu
0 stars 0 forks source link

getResourceAsStream() path fails on Android #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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(MicroEmulatorAc
tivity.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:24
6)
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.

Original issue reported on code.google.com by LatinSuD@gmail.com on 14 Jan 2010 at 10:31

GoogleCodeExporter commented 9 years ago
1. What's specified exactly in getResourceAsStream() argument when you try to 
load
TimeZone.dat?
2. After the build task is done, can you find the TimeZone.dat file in
microemu-android/bin/assets folder?

Original comment by bar...@gmail.com on 15 Jan 2010 at 10:05

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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?).

Original comment by LatinSuD@gmail.com on 15 Jan 2010 at 2:08

GoogleCodeExporter commented 9 years ago

Original comment by bar...@gmail.com on 16 Jan 2010 at 8:39

GoogleCodeExporter commented 9 years ago

Original comment by bar...@gmail.com on 18 Jan 2010 at 8:39

GoogleCodeExporter commented 9 years ago
Fix commited to trunk

Original comment by bar...@gmail.com on 26 Mar 2010 at 11:36