Java BufferedImage with Lejos NXT: Java Heap Space I'm trying to write a program for my Lego Mindstorm NXT, the program is simple, drawing some lines and saving the image in a .png file. So, I thought I'd use BufferedImage and use getGraphics to draw on it, the thing is; if I write the code:

import java.awt.image.BufferedImage;

import lejos.nxt.Button;

public class Main {

    public static void main(String[] args) {
        System.out.println("Test\n");
        BufferedImage bimg = new BufferedImage(300,300, BufferedImage.TYPE_3BYTE_BGR);
        Button.waitForAnyPress();

    }
}


When I run the program, it freezes for a while in "Linking..." and gives me the following:

Java Heap Space
Java.Lang.OutOfMemory


So the question is this: How can I use BufferedImage with Lejos without having this problem? And if there's another method of drawing lines and saving the image on a file, it would be very helpful.

EDIT:
The Java Heap Space is caused by the line 

BufferedImage bimg = new BufferedImage(300,300, BufferedImage.TYPE_3BYTE_BGR);


I've also tried using ImageIO:

import javax.microedition.lcdui.Image;
*
*
Image img = Image.createImage(300, 300);
ImageIO.write((RenderedImage) img, "png", monFichier);


It gives me the same thing. I don't know but maybe this isn't the right way to create an image with Lejos. What do you think?
I'm a little puzzled by how you are getting these results, but I am assuming you are getting an error when you run the equivalent of nxjc and nxjlink on a supported platform. i.e., you are probably invoking nxj -r ...

Furthermore, I am assuming you are basing these commands on a recent Java compiler from Oracle; version 7 or 8.

First of all, it is my understanding that java.awt.image.* is not even present. The example showed here should not even compile because the only AWT classes we have access to are java.awt.Point and java.awt.Rectangle. 

Furthermore, only some of the javax.microedition.lcdui API is implemented, so you should check the documentation to see if Image is supported in the manner you want. So, for example, ImageIO is not present.

So, the example programs you show here are not going to even compile (never mind link) with the as-shipped latest version of leJOS NXJ.

At any rate, the size of the heap for leJOS is basically all of the RAM on the brick, but it is shared with the stack and static RW memory. But I'm not convinced the message you are seeing is related to the leJOS VM runtime heap, but rather the heap of the thing that is trying to create the classes and link them into the "TinyVM" before sending them to the brick.

We don't know because you have not described exactly how you are getting this message, with what command(s), with the full output of the exception(s)!

So, if you want to solve this, we need:


The platform you are running leJOS on.
The output of %LEJOS_NXT_JAVA_HOME%\bin\javac -version (assuming Windows; you know what to do for OS X or Linux)
For that matter, what is %LEJOS_NXT_JAVA_HOME% or ${LEJOS_NXT_JAVA_HOME} set to?
The output from the command you are running. Try capturing what comes out of nxj -v -r Main
The version of leJOS NXJ you are running


Place this in the body of your question, please.