Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6827985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:19:48+00:00 2026-05-26T22:19:48+00:00

I am having trouble determining why my code gets a nullPointer exception. I’m trying

  • 0

I am having trouble determining why my code gets a nullPointer exception. I’m trying to write a swing application using a combination of Java and Clojure. I have a Clojure function that calls a function in my JPanel subclass, and I’m getting a lot of exceptions that are driving me crazy.

I’ve simplified my code as much as possible, and I’m still getting these errors.

(defn draw-state
  "Draws the current state."
  [state display]
  (do-swing (.drawBlocks display)))

Here’s the entire JPanel subclass, although I think the only relevant part is the drawBlocks function (which eventually will be replacing the blocks array):

public class TDisplay extends JPanel {


private Block[] blocks = new Block[1]; 

/**
 * Create the panel.
 */
public TDisplay() {
    setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
    setBackground(Color.WHITE);
    setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
    blocks[0] = new Block(3, 4, 0);
}

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    for (Block b : blocks) {
        if (b == null) continue;

        switch (b.colour) {
        case 0:
            g.setColor(Color.WHITE);
            break;
        case 1:
            g.setColor(Color.BLACK);
            break;
        }                               
        g.fillRect(b.x * Block.SIZE, b.y * Block.SIZE, Block.SIZE, Block.SIZE);
    }                
}

public void drawBlocks() {
    System.out.println("Hello world");
}

}

And the stack trace:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.lang.NullPointerException
at clojure.lang.AFn.run(AFn.java:28)
at java.awt.event.InvocationEvent.dispatch(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 java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:263)
at core$draw_state$fn__401.invoke(core.clj:43)
at clojure.lang.AFn.run(AFn.java:24)
... 8 more

I have the feeling that I’m missing something really obvious, and I’d appreciate any help.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:19:49+00:00Added an answer on May 26, 2026 at 10:19 pm

    How about the code that invokes draw-state — is it possible that’s passing in nulls for display?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble determining what's going on with simplexml_load_string() I'm using the below
I'm having trouble determining if it's possible, based on the amount of access I
I am having some trouble determining if two line segments are collinear because of
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I was having trouble determining what was cause my form to not submit when
I'm having trouble determining the best way to read some input in for a
My Perl isn't very good at all and I am having trouble determining why
Having trouble determining if a file name conforms to a specific convention as follows.
I'm having trouble determining the difference between CREATE SCHEMA and CREATE DATABASE. I'm of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.