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
Posts: 61
Registered: ‎06-01-2009
My Device: Not Specified
Accepted Solution

Uncaught exception: java.lang.OutOfMemoryError!

[ Edited ]

We are working on an app, it is only 80K in size and it will call to the server to request for an xml files back and put it in nodelist and then transfer into array.  and then it is on screen with the values. 

BUT, the app doesn't even able to load and the device keep loading for 5 mins and then it pops up an error message saying: "Uncaught exception: java.lang.OutOfMemoryError

 

Please help 

Message Edited by fenixlam on 06-17-2009 12:17 PM
Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

[ Edited ]

The compiled size of your app is not the issue. Somewhere in your code you are allocating new objects and keeping references to them. It sounds like there may be either a simple infinite loop or else infinite mutual recursion somewhere (perhaps among constructors, since this seems to happen during start-up). The debugger is the ideal tool for tracking down this sort of thing.

 

On second thought, mutual recursion is not so likely, since you'd probably get a stack overflow exception long before you ran out of memory.

Message Edited by Ted_Hopp on 06-17-2009 12:37 PM



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 61
Registered: ‎06-01-2009
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

But the program can run successfully in the simulator......

 

If some area is looping forever, the program should not continue to process in simulator.

 

I am trying to cut some piece of the program to test if where it is failed in the machine.

 

Will there be the problem in FileConnection or Image loading? 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

Ah. You didn't mention before that it ran in the simulator. Two main reasons for differences between the simulator and a real device are code signing and application permissions--the simulator requires neither; a real device requires both. So if, for instance, you have fall-back processing in case a file access fails, then the fall-back code will likely never be run in the simulator. Not knowing anything else about your app, I'd suggest looking for that kind of thing.

 

Also, it may or may not be important, but on what device/software version(s) is it failing, and on what version(s) of the simulator does it work?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Developer
New Developer
Posts: 16
Registered: ‎06-11-2009
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

We are using the Bold devise for the real testing and using JDE4.6 for the simulator.

 

Everything seems to work in the simulator but so many problem arise in the real machine. Please help and advise. 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

I think that Ted gave you as much advice as you are going to get without more information.

 

You need to do some more problem determination on the device, like pulling the device event log and looking for exceptions.

 

You might also make sure you have some strategic "System.out.println()" statements in your code so that you can view output on the console window and determine where you are blowing up.

 

 

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

You can try connecting the JDE debugger to the application running on the device. Perhaps you can observe the problem behavior in action if you step through the code as the app starts up.



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

Hi,

 

Try using this class for on device debbugging net.rim.device.api.system.EventLogger.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 5,339
Registered: ‎09-20-2008
My Device: ***
My Carrier: ***

Re: Uncaught exception: java.lang.OutOfMemoryError!

Run profiler in JDE and debug the application, especially the part that throws the exception.

 

Check the objects qty and size in profiler and act accordingly.

 

To get information about working with profiler in JDE open menu Help - IDE Help

Developer
Posts: 61
Registered: ‎06-01-2009
My Device: Not Specified

Re: Uncaught exception: java.lang.OutOfMemoryError!

Finally, I got the solution.

The problem is cause by temporary memory used.

In my code, there is a temporary array to carry the Bitmap when it is load in. I set the memory in 1MB and I don't gc it after it is loaded. So it is out of memory after it load about 10 pictures.

This is the code what I used. I hope this sample can help the others at next time.

public class LoadPic {
        private InputStream input;
        public EncodedImage result;
        public LoadPic (String ipic){
        //previously, I use 1024*1024 (1MB) in this temperary space.
            byte[] data = new byte[1024*80]; //now I use 80KB only.
            EncodedImage image=null;
            try {
                input = Class.forName( this.getClass().getName() ).getResourceAsStream(ipic);
            } catch (ClassNotFoundException e) {
                System.out.println("Class not found");
            }
            if(input == null) {
                System.out.println("Error: input stream is not initialized.");
            } else if (input != null) {
                System.out.println("OK: input stream is initialized.");
                try {
                    int code = input.read(data);
                    System.out.println("Total number of bytes read into buffer: " + code + " .");
                } catch (IOException e) {
                    // Handle exception.
                }
                try {
                    image = EncodedImage.createEncodedImage(data, 0, data.length);
                    //I don't type these two code to cause out of memory.
            data=null;
                    System.gc();
                } catch (IllegalArgumentException iae) {
                    System.out.println("Image format not recognized.");
                }
                   
            }
            result=image;
           
        }
    }