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
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor
Accepted Solution

Error in CodeModuleManager.createNewModule

[ Edited ]

 

I am trying to install a large MIDP app. The size of the cod is 382976. I am installing it with siblings. I have tried 2 approaches

1. Start with creating an "empty" cod

int handle = CodeModuleManager.createNewModule(totalsize);

and

int handle = CodeModuleManager.createNewModule(382976);

both approaches returns a zero handle

 

int handle = CodeModuleManager.createNewModule(3000);

returns a nonzero handle

 

I also tried to creat the first sibling segment at the first call

 

int handle = CodeModuleManager.createNewModule(totalsize, codInfo[0].getCodfile(), codInfo[0].getCodsize());

 

it gives a zero handle too.

 

I am running on the simulator. The large app installs ok when using other methods

 

Edited:

Code works for a small app

 

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Error in CodeModuleManager.createNewModule

What the.....???

 

searching the web I found this:

 

http://www.thinkingblackberry.com/archives/141

Indicating that the API documentation is all wrong!

 

2 days in the drain!!!

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Error in CodeModuleManager.createNewModule

There is something in the doc that talks about this 'problem' isn't there:  Here it is...

 

How to add sibling .cod files.
You need to write the data in two separate chunks. The first data chunk must be less than 64KB in size.

1.To write the first data chunk, invoke CodeModuleManager.createNewModule( int totalLength, byte[] data, int length ).
2.To write the second data chunk, invoke CodeModuleManager.writeNewModule( int newModuleHandle, byte[] data, int newModuleOffset, int length ).

 

Problaby just me, but I would not have expected to write the entire cod in one hit....

Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Error in CodeModuleManager.createNewModule

The method for writing a cod module in separate "chunks" described in th api documentation just does not work.

2 methods are indicated. Both indicates that you keep track of the offset where to add the "chunks"

To write the first data chunk, invoke CodeModuleManager.createNewModule( int totalLength, byte[] data, int length ).

To write the second data chunk, invoke CodeModuleManager.writeNewModule( int newModuleHandle, byte[] data, int newModuleOffset, int length ).

I can not understand "totalLength" in any other way than the length of the "total" cod

The other way is a slight variation and starts with just specifying size and no data.

Create a module without data
Invoke createNewModule() and provide the size of the module in bytes as a parameter.

int handle = CodeModuleManager.createNewModule( 3000 );

Here  I read "the size of the module" as the size of the complete cod module.

They both fail if the "total size" is large giving a handle = 0;

What works is the way it is described in the sample

http://supportforums.blackberry.com/t5/Java-Development/Programmatically-install-and-upgrade-applica...

That is a completely different way than is described in the API, You do not need to keep track of offset where to place the "chunks" and you do not need to porvide any information about "total length"

The description in the API is just plain wrong and does not work and the same documentation is in API for 6.

http://www.thinkingblackberry.com/archives/141

points this out

 

This is unacceptable. cost me lots of time and aggravation

The API documentatuion should be updated

 

 

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Error in CodeModuleManager.createNewModule

[ Edited ]

Having reviewed it again, I agree the documentation is wrong. 

 

There is a "Submit Feedback" button in the OS 5.0 documentation.  Use it and suggest a correction. 

 

And thanks for bringing this to our attention on this forum so that other people having this problem can search and find the solution here. 

Please use plain text.
Developer
ingvar_e
Posts: 551
Registered: ‎10-31-2009
My Device: Torch 9800, Bold 9700
My Carrier: Movistar, Telenor

Re: Error in CodeModuleManager.createNewModule

OK

:-)

How do we flag this thread.  Solved?

If everything seems to be under control, you're just not driving fast enough
-Mario Andretti-
Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Error in CodeModuleManager.createNewModule

I think your previous post, which points out the issues and points people to the 'thinking' article, is a good solution?

Please use plain text.
Developer
mantaker
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Error in CodeModuleManager.createNewModule

Click 'Mark as solution' , It should be somewhere near that reply.

 

Cheers,

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Please use plain text.
Regular Contributor
ManikandanP
Posts: 77
Registered: ‎09-19-2008
My Device: Blackberry 8320
My Carrier: Airtel India

Re: Error in CodeModuleManager.createNewModule

I am not able to access this page, http://www.thinkingblackberry.com/archives/141

 

Any suggestion? If anyone has this article saved, please send it to me.

 

Thanks

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: Error in CodeModuleManager.createNewModule

Not sure what has happened, but here is the content, not as well formated.

 

Loading sibling cods using CodeModuleManager

 

I recently had occasion to use the CodeModuleManager to load a module onto the BlackBerry after downloading it from a remote server. This was a bit tricky because the javadocs from RIM about CodeModuleManager are at best misleading.


The Javadocs (from 4.7) say:

 

How to add sibling .cod files.

 

You need to write the data in two seperate chunks. The first data chunk must be less thank 64KB in size.

1. To write the first data chunk, invoke createNewModule( int totalLength, byte[] data, int length ).
2. To write the second data chunk, invoke writeNewModule( int newModuleHandle, byte[] data, int newModuleOffset, int length ).

 

First of all, the writeNewModule method metioned is deprecated! But that’s not the worst problem - I’ll explain.

If we have an application with 3 sibling cods, with a total size of say 150000 bytes, you might think (as I did) that the above docs imply that you need to do something like this:


private void writeModule(byte[] cod1, byte[] cod2, byte[] cod3) {  
    int handle = CodeModuleManager.createNewModule(150000, cod1, cod1.length);  
    boolean result = CodeModuleManager.writeNewModule(handle, cod1.length, cod2, 0, cod2.length);  
    result = CodeModuleManager.writeNewModule(handle, cod1.length + cod2.length, cod3, 0, cod3.length);  
    CodeModuleManager.saveNewModule(handle);  
}


You would be wrong! The actual way to do it is:


private void writeModule(byte[] cod1, byte[] cod2, byte[] cod3) {  
    int handle1 = CodeModuleManager.createNewModule(cod1.length, cod1, cod1.length);  
    CodeModuleManager.saveNewModule(handle1);  
    int handle2 = CodeModuleManager.createNewModule(cod2.length, cod2, cod2.length);  
    CodeModuleManager.saveNewModule(handle2);  
    int handle3 = CodeModuleManager.createNewModule(cod3.length, cod3, cod3.length);  
    CodeModuleManager.saveNewModule(handle3);  
}


The BlackBerry OS knows enough to put the sibling cods together into the same module.

 

So the above Javadocs are wrong - you only need to write the data in two separate chunks, for an individual sibling cod file, if that cod file is bigger than 64kb. So actually the above code sample will work only if your sibling cods are each less than 64kb. If one of them is more you’ll need to do this:

 

int handle1 = CodeModuleManager.createNewModule(cod1.length, cod1, 64000);  
CodeModuleManager.writeNewModule(handle1, 64000, cod1, 64000, cod1.length-64000);  
CodeModuleManager.saveNewModule(handle1); 

 

Of course, only if cod1.length > 64k (I just used 64000 here to be on the safe side - you could actually use 65536 (or maybe 65535?)

 

Share and Enjoy

Please use plain text.