我正在学习 clojure,在我编写的这个非常丑陋、反惯用、愚蠢的代码中发现了一个问题:
(ns music-tag.core
(:import
(java.io.File)
(com.echonest.api.v4.EchoNestAPI)
(com.echonest.api.v4.Track)))
(def api-key "JRZSJUMBK8VOOP0L2")
(def music (new java.io.File "/home/simo/Musica/musica_mp3/Rabiosa-Shakira.mp3"))
(def echo-nest (new com.echonest.api.v4.EchoNestAPI api-key))
(def traccia (. echo-nest uploadTrack music true))
(. traccia waitForAnalysis 30)
(do (println (. traccia getArtistName) (. traccia getTitle)))
当我运行这个文件时,我得到了正确的答案(印刷艺术家和标题),但它抛出了一个异常:
simo@simo:~/music-tag$ lein run
Shakira Rabiosa (Featuring Pitbull)
Exception in thread "main" java.lang.NullPointerException
at user$eval39.invoke(NO_SOURCE_FILE:1)
at clojure.lang.Compiler.eval(Compiler.java:6465)
at clojure.lang.Compiler.eval(Compiler.java:6455)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
at clojure.main$initialize.invoke(main.clj:315)
at clojure.main$null_opt.invoke(main.clj:348)
at clojure.main$main.doInvoke(main.clj:426)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:405)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:518)
at clojure.main.main(main.java:37)
为什么?我该怎么解决???
谢谢