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
miskatonic
Posts: 83
Registered: ‎02-17-2009
My Device: Not Specified
Accepted Solution

Re-Installing a module using CodeModuleManager...

Hi,

 

I'm trying to install a module via code and I'm having some problems...

 

The module is stored in filesystem (/store/home/user) and when i try to connect using a ContentConnection I get a ClassCastException looping. If I change this to a FileConnection there's no exception but the method handler = CodeModuleManager.createNewModule(len); returns 0 all the time.

 

Java Component: 4.5.0

Tested on a Curve 8900 4.6.1.168

 

 

Some code:

 

conn = (ContentConnection)Connector.open(MYCOD_PATH); int len = (int)conn.getLength(); bais = conn.openInputStream(); if (len > 0) { byte[] data = new byte[len]; bais.read(data); handler = CodeModuleManager.createNewModule(len); boolean couldWrite = false; if (handler != 0){ couldWrite = CodeModuleManager.writeNewModule(handler, 0, data, 0, data.length); } if (couldWrite){ result = CodeModuleManager.saveNewModule(handler, true); //force override of the existing module }

 

 

 

 

Any idea?

Please use plain text.
Developer
simon_hain
Posts: 15,806
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Re-Installing a module using CodeModuleManager...

what is the value of len?
did you debug into the code and check that you actually read the file?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
miskatonic
Posts: 83
Registered: ‎02-17-2009
My Device: Not Specified

Re: Re-Installing a module using CodeModuleManager...

Hi,

 

Yes, I delete the logs in the code but I am able to see that Len is ok and ClassCastException is launched when trying to connect.

 

 

Please use plain text.
Developer
miskatonic
Posts: 83
Registered: ‎02-17-2009
My Device: Not Specified

Re: Re-Installing a module using CodeModuleManager...

Changing the handler to handler = CodeModuleManager.createNewModule(len, data, len); and saving the module does the job

 

Solved!

Please use plain text.
New Developer
sapandosi
Posts: 3
Registered: ‎11-18-2009
My Device: 8300
My Carrier: Airtel

Re: Re-Installing a module using CodeModuleManager...

Here is the complete solution

 

 

 

FileConnection conn = null;
        int len = 0;
        try {
            conn = (FileConnection) Connector.open(MYCOD_PATH);
            len = (int) conn.availableSize();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        int handler = 0;
        int result = 0;

        InputStream bais;
        try {
            bais = conn.openInputStream();

            if (len > 0) {
                byte[] data = new byte[len];
                bais.read(data);
                handler = CodeModuleManager.createNewModule(len, data, len);

                boolean couldWrite = false;

                if (handler != 0) {
                    couldWrite = CodeModuleManager.writeNewModule(handler, 0,
                            data, 0, data.length);
                }

                if (couldWrite) {
                    result = CodeModuleManager.saveNewModule(handler, true); //force override of the existing module
                }
            }
        }

        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

Please use plain text.