I am trying to write a clojure code which generates an Image with each pixel of image having a value of XOR of its x and y co-ordinates but I am getting a NullpointerException. I am not able to figure out what is going wrong in my code
Here is my code:
(ns com.test
(:import (javax.swing JFrame))
(:gen-class))
; Each pixel has color value of xor of its x and y co-ordinates
(defn generateXorList [limit]
(for [x (range limit)
y (range limit)]
[x y (bit-xor x y)]
))
(defn makeImage [seq]
(let [frameSize 250
frame (JFrame.)
gfx (.getGraphics frame)]
(.setVisible frame true)
(.setSize frame frameSize frameSize)
(.setDefaultCloseOperation frame JFrame/EXIT_ON_CLOSE)
(doseq [[x y color] seq]
(.setColor gfx (java.awt.Color. color))
(.fillRect gfx x y 1 1)
)))
;; Generate the image
(makeImage (generateXorList 250))
Here is the stacktrace
clojure.lang.Compiler$CompilerException: java.lang.NullPointerException, compiling:(/tmp/t.clj:26:1)
at clojure.lang.Compiler.load (Compiler.java:7239)
user$eval1125.invoke (form-init5557027396137860263.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6782)
clojure.lang.Compiler.eval (Compiler.java:6745)
clojure.core$eval.invoke (core.clj:3081)
clojure.main$repl$read_eval_print__7099$fn__7102.invoke (main.clj:240)
clojure.main$repl$read_eval_print__7099.invoke (main.clj:240)
clojure.main$repl$fn__7108.invoke (main.clj:258)
clojure.main$repl.doInvoke (main.clj:258)
clojure.lang.RestFn.invoke (RestFn.java:1523)
clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__623.invoke (interruptible_eval.clj:58)
clojure.lang.AFn.applyToHelper (AFn.java:152)
clojure.lang.AFn.applyTo (AFn.java:144)
clojure.core$apply.invoke (core.clj:630)
clojure.core$with_bindings_STAR_.doInvoke (core.clj:1868)
clojure.lang.RestFn.invoke (RestFn.java:425)
clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:56)
clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__665$fn__668.invoke (interruptible_eval.clj:191)
clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__660.invoke (interruptible_eval.clj:159)
clojure.lang.AFn.run (AFn.java:22)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
java.lang.Thread.run (Thread.java:745)
Caused by: java.lang.NullPointerException: null
at com.test$makeImage.invoke (t.clj:22)
com.test$eval1171.invoke (t.clj:27)
clojure.lang.Compiler.eval (Compiler.java:6782)
clojure.lang.Compiler.load (Compiler.java:7227)
user$eval1125.invoke (form-init5557027396137860263.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6782)
clojure.lang.Compiler.eval (Compiler.java:6745)
clojure.core$eval.invoke (core.clj:3081)
clojure.main$repl$read_eval_print__7099$fn__7102.invoke (main.clj:240)
clojure.main$repl$read_eval_print__7099.invoke (main.clj:240)
clojure.main$repl$fn__7108.invoke (main.clj:258)
clojure.main$repl.doInvoke (main.clj:258)
clojure.lang.RestFn.invoke (RestFn.java:1523)
clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__623.invoke (interruptible_eval.clj:58)
clojure.lang.AFn.applyToHelper (AFn.java:152)
clojure.lang.AFn.applyTo (AFn.java:144)
clojure.core$apply.invoke (core.clj:630)
clojure.core$with_bindings_STAR_.doInvoke (core.clj:1868)
clojure.lang.RestFn.invoke (RestFn.java:425)
clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:56)
clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__665$fn__668.invoke (interruptible_eval.clj:191)
clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__660.invoke (interruptible_eval.clj:159)
clojure.lang.AFn.run (AFn.java:22)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
java.lang.Thread.run (Thread.java:745)
NullPointerExceptionthrown.