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
schalk
Posts: 72
Registered: ‎06-29-2009
My Device: Not Specified

Using And Creating Resource Bundles in Eclipse

Hi everyone,

 

I know this topic has been touched on many a time but I have not been able to find a single resource that really explains the solution or method of doing this in Eclipse. I have read about creating the rrh and rrc files and that the resource interface should have the same name as the rrh/rrc files and that they must have the same name as the applications name but, the thing I do not get is how to handle the 'dummy' resource interface in Eclipse.

 

I do not understand what is meant by creating a dummy resource interface but not adding it to the project... If I reference for example MyAppResource inside a class and it cannot find this interface in it's project package structure it is not going to compile. If anyone has any advice, can point me to some article, KB, video, anything :smileywink: I will be extremely pleased. Looking forward to hear fro the communtiy in this regard.

 

Kind Regards,

Schalk Neethling 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Using And Creating Resource Bundles in Eclipse

When you use resources on the BlackBerry you pass a index value to the getString, etc. function. There is no need for this index other than to get the resource so the BlackBerry JDE and Eclipse create a "Dummy" interface that is stored in the temp file folder in Windows and it simply stores a bunch of fields with the resource HashCode, name, and the index values.


In Eclipse right click your src folder, choose New->Other->BlackBerry->BlackBerry Resource File. The "Dummy" interface has "Resource" automatically appended to it so if your resource is called "MyAppResources" the interface is going to be "MyAppResourcesResource." To use this I usually create a internal static ResourceBundle field in the class that has the "main" method.

 

public class Main extends UiApplication
{
    static ResourceBundle _resources=ResourceBundle.getBundle(MyAppResourcesResource.BUNDLE_ID, MyAppResourcesResource.BUNDLE_NAME);

    public static void main(String[] args) { /* CODE */ }
}

 

Then to get something like a string call getString or getStringArray and pass in the index:

 

public void PrintHelloWorld
{
    System.out.println(Main._resources.getString(MyAppResourcesResource.HELLO_WORLD_STRING));
}

 

Hope that anwsered your question.

---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.
Please use plain text.
Developer
schalk
Posts: 72
Registered: ‎06-29-2009
My Device: Not Specified

Re: Using And Creating Resource Bundles in Eclipse

Hi there,

 

Thanks so much for your answer, it has gotten me about 90% of the way I believe. I deleted all of my resource files (rrh, rrc and the dummy java file) and then recreated all of them accept the java file. I recreated that file and placed it in the Windows tmp folder. I created the static resource definition as you suggested and everywhere I am reading resource values I am using using

 

Main._resources.getString(MyAppResource.KEY); 

 

When trying to build the app in Eclipse everything is resolved, even the keys in the resource file however, it fails to successfully complete the build because it cannot find the  MyAppResource file :smileysad: Now, as mentioned before I have read about creating a dummy one but not adding it to the project, I guess this is where the file in the Windows tmp folder comes in, but it does not seem to do the trick. Any ideas how to fix this? If I can just get Eclipse to resolve this last reference I am in business. Thanks for all of your help.

 

Kind Regards,

Schalk 

Please use plain text.
Developer
schalk
Posts: 72
Registered: ‎06-29-2009
My Device: Not Specified

Re: Using And Creating Resource Bundles in Eclipse

Ok, this is what I have tried so far. I removed the previously mentioned .java class from the Windows tmp folder. I then created a new project in the same workspace and added the file there, in the BBApps build path I set the Resources project as a project to be available on the build path but, I do not include the project in the order and export area. Also, the Resources project was created as just a plain Java project and not a BlackBerry project.

 

I can then build the BBApp successfully however, when trying to run it on the simulator, I still get exactly the same error :smileysad: What am I missing?

 

Kind Regards,

Schalk 

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Using And Creating Resource Bundles in Eclipse

Ok, first off (as you said in your second post that you removed this) don't creat that "dummy" file. Eclipse/BB JDE will do this for you.

 

Second rember that any resource you create will have the word "Resource" automatically appended. So if you create MyAppResources than when you go to use it you would call MyAppResourceResource.

 

If you need an example project look at the "localizationdemo" in the samples folder. The classes used in it implement the "dummy" interface so that it doesn't need to reference it over and over and can instead use it like a local variable.

---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.
Please use plain text.
New Developer
Monika
Posts: 9
Registered: ‎12-23-2009
My Device: Not Specified

Re: Using And Creating Resource Bundles in Eclipse

Hi,

I am new in blackberry,i want to know why we are using resource bundle and what is the basic purpose to add .rrc and .rrh file in our application.

 

 

Please use plain text.
Developer
anilsisodiya
Posts: 193
Registered: ‎04-27-2009
My Device: Not Specified

Re: Using And Creating Resource Bundles in Eclipse


Monika wrote:

Hi,

I am new in blackberry,i want to know why we are using resource bundle and what is the basic purpose to add .rrc and .rrh file in our application.

 

 


We are using resource bundle to make localization of application easier and faster..rrh .rrc provides key to access particular string from resource bundle.

Please use plain text.
New Developer
Monika
Posts: 9
Registered: ‎12-23-2009
My Device: Not Specified

Re: Using And Creating Resource Bundles in Eclipse

How We create rrc and rrh file in our blackberry application?

Please use plain text.
Developer
rcmaniac25
Posts: 1,804
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1154, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Using And Creating Resource Bundles in Eclipse

RIght click the namespace that you want the resource in and select New->Other, then under the BlackBerry category choose BlackBerry Resource 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.
Please use plain text.