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
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified
Accepted Solution

Better documentation for getResourceAsStream?

Here's the RIM documentation for Class.getResourceAsStream():


RIM Implementation Notes: This method searches for the resource starting from the directory in which the current project's JDP file resides. By default, it is assumed that this JDP file resides in the parent directory of the current project's package space. Thus, the package space directory structure (e.g., com/rim/package_name) is prepended to name so that the search begins relative to this package space, i.e., in the current project's source directory. However, if the current project's JDP file does not reside in its assumed location, the above behaviour will prevent the resource from being found. In this case, the user should prepend a forward slash (/) to the resource name before calling getResourceAsStream. This treats name as an absolute path, which is compared with a tree rooted at the location of the JDP file.

This is terribly confusing (when getResourceAsStream executes, it's not on the user's development machine and neither the JDP file nor the project source directory are accessible) and is certainly wrong for the Eclipse plug-in, which has done away with JDP files. Unfortunately, this excerpt is from the latest and greatest OS 6 docs.

 

Is there any more coherent explanation of the search path that getResourceAsStream uses? Some realistic examples of different cases, that show when a leading '/' is needed, when to add a path prefix, etc., would be very helpful. A recent post described a way to open an input stream to a resource in another module, since getResourceAsStream() does not seem to work for that:

 

ContentConnection cc = (ContentConnection)Connector.open("cod://module/path/file.txt");

Is this recommended? Or is there perhaps a way for getResourceAsStream() to search dependent .cod files the way that Bitmap.getBitmapResource() does?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Better documentation for getResourceAsStream?

The cod:// protocol is not supported.

 

Class.getResourceAsStream essentially accepts a file path that points to a file packaged within your COD file.  The path mirrors the package structure in the cod file. 

 

The description pertains to the BlackBerry JDE and should be clarified for Eclipse. 

 

I have forwarded your feedback to the documentation team using the feedback form here:

 

https://www.blackberry.com/DocsFeedback/?title=API+Reference&source=External&version=6.0.0&classname...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Better documentation for getResourceAsStream?

Thanks, Mark. I take it, then, that aside from bitmaps, there is no supported way for code in one COD file to access a resource packaged in another COD file (e.g., a dependent library)?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Better documentation for getResourceAsStream?

Not directly.  The library could expose this via a method call of its own.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Tashani
Posts: 8
Registered: ‎12-23-2009
My Device: Not Specified

Re: Better documentation for getResourceAsStream?

is there any solution ?

 

Is there any more coherent explanation of the search path that getResourceAsStream uses?