Hi all
I'm on a program of reading incoming images which comes as byte arrays through a socket and convert them back to images at j2me client using the following method.
The programs works fine for some time. But after few minutes it prints the errorCode:javax.microedition.lcdui.Image.createImage();
Folowing is client code method (it's a thread)java.lang.OutOfMemoryError: Java heap space
at java.awt.image.BufferedImage.getRGB(Unknown Source)
at com.sun.kvem.midp.GraphicsBridge.loadImage(Unknown Source)
at com.sun.kvem.midp.GraphicsBridge.createImageFromData(Unknown Source)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.kvem.sublime.MethodExecution.process(Unknown Source)
at com.sun.kvem.sublime.SublimeExecutor.processRequest(Unknown Source)
at com.sun.kvem.sublime.SublimeExecutor.run(Unknown Source)
Reading of byte arrays through socket communication works fine and they contain no problem.Code:public void run() { super.run(); short length; while (true) { DataInputStream din = null; try { din = new DataInputStream(in); length = din.readShort(); // to determine next data packet size byte[] arr = new byte[length]; // next data packet store here din.readFully(arr); //read image //##################################### img = Image.createImage(arr, 0, arr.length); //##################################### canvas.setImage(img); ChangeImage.sleep(50); } catch (Exception ex) { ex.printStackTrace(); } } }
But problem is
When I comment the above line it works fine for indefinite time period. No problem at all.Code:img = Image.createImage(arr, 0, arr.length);
I need to know that whether it's not flush old images?
Or are there any other method to convert byte array to images?
Please help me.

Reply With Quote

