03-11-2009 11:17 AM - edited 03-11-2009 11:18 AM
I have created an application and I want to load the necessary images and other resources from a separate library so that I can make one version of the app that works on multiple device types, simply by supplying a different resource library.
(Note - I am *not* referring to localization)
For images, this is very easy to do:
EncodedImage.getEncodedImageResource( "module", "imagename" )
However, I'm trying to load an arbitrary text file that contains some configuration information and I can't figure out how to load the resource.
I tried this:
Create a distinct package name and insert a Dummy class in the library.
Call Class.fromName( "distinctPackage.Dummy" )
On the Class instance returned, call .getResourceStream( "resourcename" )
However, I always, always get null in the call to the getResourceStream.
I understand there would be some concerns over the ability of an application to load resources from arbitrary modules, but since this is already allowed for images, is there anyway to do this for non-image resources?
03-11-2009 01:49 PM
To view local html file I use the following code:
BrowserSession session = Browser.getDefaultSession(); session.displayPage("cod://modulename/document.htm
use this approach to access file resource in another module
03-11-2009 02:23 PM
Unforunately, that doesn't appear to work. The debug output shows a rather unfortunate name for the resource it's trying to locate. (mypackage/cod:/targetmodule/targetpackage/targetr
But thanks for the idea.
03-11-2009 02:39 PM
Do not specify package name when you're getting resource by way I described.
Place your resource at the package root and specify path in exact format I described.
It should work.
03-11-2009 02:59 PM
Well, if I continue to try to use getResourceAsStream it gives me the bad resource name.
Are you suggesting that I try loading the resource using the browser command?
For reference, I'm trying:
stream = getClass().getResourceAsStream("cod://" + _resourceFile + "/Layout.properties");
03-11-2009 03:26 PM - edited 03-11-2009 03:28 PM
_resourceFile has to be a cod-file name without .cod extension.
for example for cod file: myLibrary.cod and file Layout.properties located at the package root folder the code will be as follows:
Please note that all names and path are case sensitive
03-11-2009 03:49 PM
So, in order to ensure my files were at the root I double-checked it by examining the jar file that's created during the compilation process. The file Layout.properties does appear in the root of this jar, so I'm working on the assumption that it is the root of the cod file.
For the name of the library, it is a copy-and-paste of the library name as set in the RIM properties, so I can only assume it also matches.
The debug output is:
FRIDG: could not find lyrix/cod:/LyrixResource_240x260/Layout.properties
It appears that no matter what, if the resource name doesn't start with / it injects the package of the calling class in front of the cod reference. (Yes, despite the above appearance, I have tried // and //// in order to try to get the right number of / after the cod: part)
03-11-2009 04:25 PM - edited 03-11-2009 04:25 PM
You're right, I was wrong.
It does not work when accessing another module. Sorry.
Just checked it on my computer in several ways.