Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 10
Registered: ‎03-11-2009
My Device: Not Specified

Load resources from library

[ Edited ]

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?

Message Edited by Kiyote on 03-11-2009 11:18 AM
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Load resources from library

New Developer
Posts: 10
Registered: ‎03-11-2009
My Device: Not Specified

Re: Load resources from library

Yes, I have reviewed that article.  The problem is that works only for resources contained inside your application.  I'm trying to load a resource from an ancillary library.
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Load resources from library

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

 

New Developer
Posts: 10
Registered: ‎03-11-2009
My Device: Not Specified

Re: Load resources from library

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/targetresource)

 

But thanks for the idea.

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Load resources from library

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.

New Developer
Posts: 10
Registered: ‎03-11-2009
My Device: Not Specified

Re: Load resources from library

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");
 

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Load resources from library

[ Edited ]

_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:

 

 

stream =

getClass().

getResourceAsStream(

"cod://myLibrary/Layout.properties");

 

Please note that all names and path are case sensitive

 

Message Edited by tbilisoft on 11-03-2009 07:28 PM
New Developer
Posts: 10
Registered: ‎03-11-2009
My Device: Not Specified

Re: Load resources from library

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:

Starting LyrixClient
Started LyrixClient(126)
Foreground LyrixClient(126)
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)

Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Load resources from library

[ Edited ]

You're right, I was wrong.

 

It does not work when accessing another module. Sorry.

 

Just checked it on my computer in several ways.

Message Edited by tbilisoft on 11-03-2009 08:25 PM