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 Contributor
eye776
Posts: 9
Registered: ‎04-23-2010
My Device: 8530
Accepted Solution

How can I place resources in a separate cod?

I've seen it mentioned a few times and I'd REALLY need to know this.

How can I place my resources in a different, updateable cod? (I need to read some text-only configuration files that control the application's features.)

 

I created an "appNameres.cod" file (contains config text files), and it installs to the phone.

It also appears in the "modules" listing on the device (listed as "appNameres").

 

However, when I use

 

String filename = new String("cod://appNameres/appconfig.cfg");
InputStream is = file.getClass().getResourceAsStream(file);

It doesn't find the file I need.

 

Can anyone help me?

 

 

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: How can I place resources in a separate cod?

I have a simple Class in my separate resources COD that I pass what resource name I want and it returns the Stream to it. It might not be the way that you want it but it reduces the problems of making it work.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Contributor
eye776
Posts: 9
Registered: ‎04-23-2010
My Device: 8530

Re: How can I place resources in a separate cod?

Interesting idea, but could I ask you to provide with a bit more info?

 

How do I call the class?

 

Say I have

 

class ResLoader
{
  public static InputStream loadResource(String filename)
  {
    InputStream is = file.getClass().getResourceAsStream(filename);
    return is;
  }
}

 this class.

 

 HOW exactly do I use it (sorry for the caps but I am kind of desperate here :smileyhappy: ).

 

 

 

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: How can I place resources in a separate cod?

Something like:

class Res
{
     public static InputStream getResourceStream(String file)
     {
          return Res.class.getResourceAsStream(file);
     }
}

Just make sure you use a class in that COD file so it looks for resources in that COD file.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Contributor
eye776
Posts: 9
Registered: ‎04-23-2010
My Device: 8530

Re: How can I place resources in a separate cod?

[ Edited ]

Okay, I'm being borderline stupid here.

 

I added

 

import rimbbresloader;

...

InputStream is = rimbbresloader.loadResourceFile("appconfig.cfg");

...

 

 

And when I hit build on the main project, it dies with the error:

 

[javac] C:\Work\proj\work\fctmain.java:1973: cannot find symbol
[javac] symbol : variable rimbbresloader
 [javac] location: class fctmain
[javac] InputStream is = rimbbresloader.loadResourceFile("appconfig.cfg");
[javac] ^
[javac] 1 error

Also I (kinda have to) use eclipse. How could I import the blackberry JDE-built library into eclipse?

 

PS: Before getting this job I only used NetBeans (a bit), Code::Blocks and Visual Studio, oh and notepad. Eclipse and ant are pretty much arcane magic :smileyvery-happy: to me.

 

New Contributor
eye776
Posts: 9
Registered: ‎04-23-2010
My Device: 8530

Re: How can I place resources in a separate cod?

I've finally managed to build the application, loaded the library resource *.cod to the simulator, loaded the app *.cod to the simulator but I get the following error : "Can't find entry point".

 

The application does not run.

New Contributor
eye776
Posts: 9
Registered: ‎04-23-2010
My Device: 8530

Re: How can I place resources in a separate cod?

@rcmaniac2: Okay! I've managed to make it run. And it loads the resources too. :smileyvery-happy:

 

Now, I have another issue, the library requires for permissions to be set to "Allow".

Otherwise it gives me "Interprocess Communication" error and quits.

Any points on that?

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: How can I place resources in a separate cod?

Do you have the resources COD compiled as a Library?

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
schepurny
Posts: 168
Registered: ‎11-22-2009
My Device: 9000 Bold, 8300 Curve

Re: How can I place resources in a separate cod?

I think you're getting that error because accessing a COD from another COD requires the COD's to be signed, or have the permissions set to allow the same in your settings.

Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.997 Dev OS, Z30 (STA100-5)-10.3.1.997 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: How can I place resources in a separate cod?

I have a COD that contains resources and a COD that contains code, I never have to sign the resource COD and the COD that contains COD only needed to be signed when I added functions that required signing so I don't think you need to sign it in order to get it to work.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.