0

I'm having trouble getting some code working in Eclipse. It is Java code with elements from Processing and it works in the Processing IDE but gives an immediate null pointer exception in Eclipse. It also involves another library called Picking. I have other Processing code working fine in Eclipse, so I suspect it has something to do with the Picking library.

The Picking jar is on my build path and based on the stack trace I think it's being accessed just fine.

Here is the stack trace:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at processing.opengl.PJOGL.enable(PJOGL.java:1640)
at processing.opengl.PGraphicsOpenGL.blendModeImpl(PGraphicsOpenGL.java:5947)
at processing.core.PGraphics.blendMode(PGraphics.java:1842)
at processing.core.PGraphics.defaultSettings(PGraphics.java:952)
at processing.opengl.PGraphicsOpenGL.defaultSettings(PGraphicsOpenGL.java:2003)
at processing.core.PGraphics.checkSettings(PGraphics.java:892)
at picking.Buffer.callCheckSettings(Unknown Source)
at picking.Picker.<init>(Unknown Source)
at PickingDemo.setup(PickingDemo.java:29)
at processing.core.PApplet.handleDraw(PApplet.java:2281)
at processing.opengl.PJOGL$PGLListener.display(PJOGL.java:862)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:652)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:636)
at javax.media.opengl.awt.GLCanvas$10.run(GLCanvas.java:1284)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1106)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:981)
at javax.media.opengl.awt.GLCanvas$11.run(GLCanvas.java:1295)
at javax.media.opengl.Threading.invoke(Threading.java:193)
at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:595)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:308)
at java.awt.Component.dispatchEventImpl(Component.java:4736)
at java.awt.Component.dispatchEvent(Component.java:4488)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674)
at java.awt.EventQueue.access$400(EventQueue.java:81)
at java.awt.EventQueue$2.run(EventQueue.java:633)
at java.awt.EventQueue$2.run(EventQueue.java:631)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$3.run(EventQueue.java:647)
at java.awt.EventQueue$3.run(EventQueue.java:645)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:644)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

And here is the code:

import picking.*;
import processing.core.*;

public class PickingDemo extends PApplet{

// Declare a Picker object to do the picking.
Picker picker;

// Set up variables for the scene.
float r = (float) 0.0;
int[] colors = {
        color(064,064,064), // Black
        color(255,000,000), // Red
        color(000,255,000), // Green
        color(000,000,255), // Blue
        color(255,255,000), // Yellow
        color(255,000,255), // Purple
        color(000,255,255), // Cyan
        color(255,255,255) }; // White
int bgcolor = color(32);

public void setup(){
    // Set the size, and make this a 3D sketch.
    size(300,300, P3D);
    // Set up the picking object.
    picker = new Picker(this);
}

public void draw(){
    // Define a variable to track the current object's ID.
    int currentID = 0;
    // The background's ID is always -1
    background(bgcolor);
    lights();
    noStroke();
    translate((float) (width/2.0), (float) (height/2.0), (float) (30));
    rotateY(r);
    r= (float) ((r+0.01)%TWO_PI);
    for(int x=-1;x<2;x++){
        for(int y=-1;y<2;y++){
            for(int z=-1;z<2;z++){
                // Each box has a different object ID, so you have to tell the picker which ID to use. 
                picker.start(currentID);
                pushMatrix();
                scale(40);
                translate(x,y,z);
                if(x*y*z != 0){
                    // Each box is has a different color.
                    fill(colors[currentID]);
                    // Draw the box.
                    box(1);
                    currentID++;
                }
                popMatrix();
                // Tell the picker to stop using the ID, since we don't want any other objects to use this ID.
                picker.stop();
            }
        }
    }

    // See the click buffer. Warning: Heavy code.
    //loadPixels();
    //picker.getBuffer().loadPixels();
    //for( int i = 0; i < width * height; i++){
    //  pixels[i] = 200 * picker.getBuffer().pixels[i];
    //}
    //updatePixels();

}

public void mouseClicked(){
    // Get the object ID at the mouse's position.
    int mouseID = picker.get(mouseX,mouseY);
    println( mouseID );
    if(mouseID!=-1){
        // Set the background to the same color (but darker) to indicate which box was clicked.
        bgcolor = color( red(colors[mouseID])/2, green(colors[mouseID])/2, blue(colors[mouseID])/2 );
    } 
}

}

Thanks in advance for any help you can provide.

morten.c
  • 3,414
  • 5
  • 40
  • 45

1 Answers1

0

If the issue is eclipse not seeing the picking library then you need to add the picking library jar to the eclipse project and add it to the build path.

Try this:

  1. Create a folder named libs(if you don't already have one in your project)
  2. Copy the picking library .jar file to the that folder
  3. Right click the picking library .jar file and select Build Path > Add to Build Path
George Profenza
  • 50,687
  • 19
  • 144
  • 218