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: 103
Registered: ‎05-05-2009
My Device: Not Specified
Accepted Solution

how run class loader system in blackberry ?

 

How does class loader system run in blackberry ?

 

I have some questions

 

* can I load a class with spesific file name. for example, I have a file "myclass.txt" in cod. and it is a class file. can I load it ?

       can I load class like this: Class.forName("/myclass.txt");

 

 

* I can only load class that's names end .class. is it a must that  file names end with ".class" ?

 

* I use, Class.forName to load classes. is there any other way to load them ?

 

* If a class has some function that is not in device OS, I cannot load it. But, in BlackBerry, OS doesnt allow run application. however, OS should throw exception when I try to load that class. isnt it ?

Developer
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 run class loader system in blackberry ?

You don't have the questions numbered but I'll go in order:

  1. No
  2. Since #1 is no, this questions doesn't apply
  3. No
  4. ?, what? Based on what I think you might be trying to ask, it's no as well.

The only way to load classes is with Class.forName.

 

Even RIM does this* (just debug through RIM's OS functions), they have some device/API specific class, call Class.forName, the class has "loading functions" and the function that calls Class.forName will call one of those loading functions to get the specific class.

 

*Found from debugging a I/O connection.

 

But there is no ClassLoader on BlackBerry.

---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 Developer
Posts: 103
Registered: ‎05-05-2009
My Device: Not Specified

Re: how run class loader system in blackberry ?

last question about trying load class that has newer functions.

 

for example:

 

 

interface SpellCheckable {
	public void checkSpell(Field f,boolean check);
}

class SpellCheck implements SpellCheckable {
	public void checkSpell(Field f,boolean check) {
		f.setNonSpellCheckable(check);
	}
}


try {
     Class c = Class.forName("SpellCheck");
     SpellCheckable sp = (SpellCheckable)c.newInstance();
} catch (Exception e) {
}


 

can I trying to load SpellCheck class in 4.2.0 version like that ?

 

I think, If OS that has not  setNonSpellCheckable function, I cannot load class. But, I cannot start program because, OS throws "Field has not setNonSpellCheckable", even I dont run that function or SpellCheck class.

 

 

 

 

 

Developer
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 run class loader system in blackberry ?

The way J2SE loads classes/functions is "as it is needed" so if you tried something like that or used ClassLoader it would only "see" setNonSpellCheckable if it was called.

 

On BlackBerry it is loaded when the whole class is loaded, so when SpellCheck is loaded the native (no developer access) ClassLoader reads everything and says "wait, I don't have this call in here, even though it might not get called I don't want to take the risk."

 

Does that make sense?

 

A workaround would be something like making a separate COD file with device specific function calls and then calling them, this way if it is not supported on that API version it doesn't get coded into the device specific 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 Developer
Posts: 103
Registered: ‎05-05-2009
My Device: Not Specified

Re: how run class loader system in blackberry ?

OK, I see.

 

I can do it in some j2me device. but, blackberry doesnt allow. I think also like you. seperate them in other cod file. managing this is hard but it is only way for solution.

 

thank you

Developer
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 run class loader system in blackberry ?

Yea its not the simplest but it is an unintended side-effect of how RIM built there VM. On a positive note it does allow for increased flexibility, write the app and have all device specific libraries separate. Now if a new app comes out all you change is some GUI elements in the separate library and you now support a new device.

---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.