My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 27: getResourceAsStream() path fails on Android
2 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Mar 2010


 
Reported by LatinSuD@gmail.com, Jan 14, 2010
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
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?
Jan 15, 2010
#3 LatinSuD@gmail.com
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
Project Member #4 bar...@gmail.com
(No comment was entered for this change.)
Status: Accepted
Jan 18, 2010
Project Member #5 bar...@gmail.com
(No comment was entered for this change.)
Labels: Milestone-3.0
Mar 26, 2010
Project Member #6 bar...@gmail.com
Fix commited to trunk
Status: Fixed

Powered by Google Project Hosting