clojure.lang.Compiler.load(...) produces NullPointerException

89 views
Skip to first unread message

Alexey Matveev

unread,
Mar 16, 2015, 6:31:36 PM3/16/15
to clojure...@googlegroups.com
Hi,
First of all thanks for this project.

I want to use clojure from java side on android.
When I try load some clojure forms, like:

clojure.lang.Compiler.load(new StringReader("(+ 2 2)"));

NPE occurs inside DalvikDynamicClassLoader class.

java.lang.NullPointerException: Attempt to invoke virtual method 'char[] java.lang.String.toCharArray()' on a null object reference
at java.io.File.fixSlashes(File.java:185)
at java.io.File.<init>(File.java:134)
at clojure.lang.DalvikDynamicClassLoader.defineMissingClass(DalvikDynamicClassLoader.java:84)
at clojure.lang.DynamicClassLoader.defineClass(DynamicClassLoader.java:46)
at clojure.lang.Compiler$ObjExpr.getCompiledClass(Compiler.java:4808)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3968)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:6706)
at clojure.lang.Compiler.analyze(Compiler.java:6499)
at clojure.lang.Compiler.eval(Compiler.java:6764)
at clojure.lang.Compiler.load(Compiler.java:7194)
at clojure.lang.Compiler.load(Compiler.java:7159)

as I understand *compile-path* is not set and temporary compile directory can't  be created. 

I use 'clojure-1.7.0-alpha5.jar' from clojars

Thnaks in advance for help.

Alexander Yakushev

unread,
Mar 17, 2015, 2:32:23 AM3/17/15
to clojure...@googlegroups.com
Hello Alexey,

To use dynamic compilation on Android you have first to initialize it. Neko does it by default when you call neko.init/init, but you can also do it manually (if you don't use Neko). This namespace is what you need http://clojure-android.github.io/neko/#neko.compilation

--
You received this message because you are subscribed to the Google Groups "clojure-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-andro...@googlegroups.com.
To post to this group, send email to clojure...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-android.
For more options, visit https://groups.google.com/d/optout.

Alexey Matveev

unread,
Mar 17, 2015, 9:14:06 AM3/17/15
to clojure...@googlegroups.com
Thanks for reply.

This works well for me:

 final File cacheDir = new File(getCacheDir(), "clojure_repl");
            cacheDir.mkdirs();
            final String path = cacheDir.getAbsolutePath();
            System.setProperty("clojure.compile.path", path);

RT.var("clojure.core", "*compile-path*")
                    .alterRoot(Clojure.var("clojure.core", "str"), StringSeq.create(path));
Reply all
Reply to author
Forward
0 new messages