Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null pointer error when mixing JButton and PApplet. #1937

Closed
kvlinden opened this issue Jul 3, 2013 · 5 comments
Closed

Null pointer error when mixing JButton and PApplet. #1937

kvlinden opened this issue Jul 3, 2013 · 5 comments

Comments

@kvlinden
Copy link

kvlinden commented Jul 3, 2013

The (stripped down) code attached below throws the following null-pointer error:

Exception in thread "Animation Thread" java.lang.NullPointerException
at processing.core.PApplet.handleDraw(PApplet.java:2301)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
at processing.core.PApplet.run(PApplet.java:2141)
at java.lang.Thread.run(Unknown Source)

Version information:

  • Processing, v2.0b8 and later (it works with v2.0b7 and earlier).
  • Java JRE 7, 1.7.0_06.

thanks,

kvlinden

------FaceController.java-------------------------------
import javax.swing.JButton;
import javax.swing.JFrame;

public class FaceController extends JFrame {

public FaceController() {
    FacePanel facePanel = new FacePanel();
    facePanel.init();
    add(facePanel);

    // Under Java jre 7 (1.7.0_06), the following JButton statement produces a null pointer error:
    //
    // Exception in thread "Animation Thread" java.lang.NullPointerException
    //         at processing.core.PApplet.handleDraw(PApplet.java:2301)
    //         at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:243)
    //         at processing.core.PApplet.run(PApplet.java:2141)
    //         at java.lang.Thread.run(Unknown Source)
    //
    // If you remove this statement OR move it to the beginning of
    // FaceController(), the null pointer error goes away.
    //
    JButton myButton = new JButton("button");
}

public static void main(String[] args) {
    FaceController controller = new FaceController();
    controller.pack();
    // controller.setVisible(true);
}

}

------------FacePanel.java----------------------------------
import processing.core.PApplet;

public class FacePanel extends PApplet {
// Removed all this code and still got the error.
}

@aengelke
Copy link
Contributor

aengelke commented Jul 4, 2013

PApplet is an Applet, so you have to call the functions to embed an Applet...

@kvlinden
Copy link
Author

kvlinden commented Jul 8, 2013

Hmm...
The code pasted above pretty much follows the example of how to embed an Applet in a SWING application shown here:

 http://processing.googlecode.com/svn/trunk/processing/build/javadoc/core/processing/core/PApplet.html

But neither my code,nor the example code (modifed a shown below) work after v2.0b7.

ideas?

kvlinden

--- Modified Embedded.java example code ----------------------------------
package work.gui;

import java.awt.BorderLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class ExampleFrame extends JFrame {

public ExampleFrame() {
    super("Embedded PApplet");

    setLayout(new BorderLayout());
    Embedded embed = new Embedded();
    add(embed, BorderLayout.CENTER);

    // important to call this whenever embedding a PApplet.
    // It ensures that the animation thread is started and
    // that other internal variables are properly set.
    embed.init();

    // Add this button to get the null pointer error. 
    JButton myButton = new JButton("test");
}

// Add this main() method to run the application.
public static void main(String[] args) {
    ExampleFrame controller = new ExampleFrame();
    controller.pack();
    controller.setVisible(true);
}

}

@benfry
Copy link
Contributor

benfry commented Jul 9, 2013

Please use the forum for discussions; this doesn't appear to be a bug.

@benfry benfry closed this as completed Jul 9, 2013
@kvlinden
Copy link
Author

kvlinden commented Jul 9, 2013

I see that there is a detailed discussion of this issue here:
http://forum.processing.org/topic/embedding-papplet-with-jframe-swing-error-on-jbutton
My apologies for not searching the forums more carefully.

kvlinden

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants