NullPointerException on size(); method in Eclipse

Hi, I had some code that worked correctly in Processing, but after I imported it to Eclipse I get a NullPointerException on the size() method. Changing its value to anything else doesn't work, I still get the exception at runtime. Can anybody please help? It seems like an unlikely thing to get.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at processing.core.PApplet.size( at processing.core.PApplet.size( at Heatmap.setup( at SignalTester.closeButtonActionPerformed( at SignalTester.access$0( at SignalTester$1.actionPerformed( at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.JToggleButton$ToggleButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$ Source) at java.awt.EventQueue$ Source) at Method) at$1.doIntersectionPrivilege(Unknown Source) at$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$ Source) at java.awt.EventQueue$ Source) at Method) at$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at Source)

And here is my code. I am running the class using a GUI, hence all the swing things in the error stack.

import processing.core.*;

public class Heatmap extends PApplet {

        /** This program outputs a heatmap over the floor plan.
         *  Requires: 1) position & signal strength txt file
         *            2) floor plan png file

    private static final long serialVersionUID = 1L;

    public void setup() {
        size(200, 200);
        int green = 0;
        int red = 0;
        int signal;

        // Load input file
        String[] lines = loadStrings("output2.txt");

        // Tokenize inputs
        String[] numbersString = split(lines[0], ' ');

        // Convert String[] to int[]
        int[] numbers = new int[numbersString.length-1];
        for (int i=0; i < numbersString.length-1; i++) {
            numbers[i] = Integer.parseInt(numbersString[i]);

        // initialize colours array
        int[] colours = new int[(numbers.length/2)*3];
        // Determine colours from signal strength
        for (int j=0; j<numbers.length/2; j++) {
            signal = -numbers[2*j + 1];
            if (signal < 50) {
                green = 255;
                red = (signal-19)*6;
            else if (signal >= 50) {
                red = 255;
                green = -(signal-81)*6;

            // Populate colours array
            colours[j*3] = numbers[j*2];
            colours[j*3 + 1] = red;
            colours[j*3 + 2] = green;

        // End signal strength to colour conversion
        // Begin heatmap rendering

        int cols, rows;
        int number = 0;
        int[] centreX = new int[602];   // 43 columns x 14 rows
        int[] centreY = new int[602];

        int redFill = 0;
        int greenFill = 0;

        PImage img;
        img = loadImage("properfloorplan2nolabels.png");
        image(img, 0, 0);

        cols = 4600/107;  // = 43 rounded up
        rows = 1472/107;  // = 14

        for (int j=0; j<rows+1; j++) {
            for (int i=0; i<cols+1; i++) {
                int x = i*107;
                int y = j*107;
                for (int k=0; k<colours.length/3; k++) {
                    if (number+1 == colours[k*3]) {
                        // Square has a colour
                        redFill = colours[k*3 + 1];
                        greenFill = colours[k*3 + 2];

                        // Colour in the square
                        fill(redFill, greenFill, 0, 150);
                        stroke(0);  // black lines
                        rect(x-15, y+50, 107, 107);  // adjusted to line up with room corner
                    else {
                        // Else it's a normal transparant square
                        fill(0, 0, 0, 0);
                        rect(x-15, y+50, 107, 107);  // adjusted to line up with room corner

                centreX[number] = (x-40) + (107/2);
                centreY[number] = (y+60) + (107/2);

                // Grid numbers
                //fill(0, 102, 153, 255);
                //text(number+1, centreX[number], centreY[number]);


    public void draw() {




  • Answer ✓

    Never really used other IDEs for Processing yet. But I believe we need a class w/ a main() in it, right? [..]

    Pick any Processing working program and use Processing IDE's export feature (CTRL+E).
    You're gonna find a valid ".java" file there. You gotta mime that template when using other IDEs! 8-X

    Most important step is ignite Processing's PApplet.main() method inside main()! >-)

  • Thanks, that helped. I included the main method in the Processing java class and it worked. I've got another related question, in the main method the argument passed to it is "--present" "(name of class)". Is the "--present" that which is causing a window to open and present the drawing? Is there any way to turn it off? Since I just want it to output a jpeg file for me too look at later.

  • AFAIK, "--present" is for fullscreen! ~:>

  • Ok thanks, I just got rid of it and now a little grey screen pops up. But I can just close it, better than my little laptop that I'm using to gather data rendering a massive image :)

    Thanks a lot for your help!

  • Hi martyn16, where exactly did you include the main method in your code?

Sign In or Register to comment.