Hi,
I'm having trouble calling method of gen-class'ed classes on Android.
On Android, it is recommended to compile against the latest android.jar.
When you run an app on real devices, some classes and methods are missing
because runtime android.jar is usually older.
Say, the latest Activity.java has a method which takes SomeNewClass as an
argument which doesn't exist in version 1 of Activity.java.
Version1:
public class Activity {
public void mymethod() {}
}
Version2:
public class Activity {
public void mymethod() {}
public void mymethod(SomeNewClass a) {}
}
When you gen-class a class which extends Activity version2, the generated
class has mymethod(SomeNewClass) automatically.
The problem occurred when I try to call the method dynamically. It crashes
because Class.getMethods() throws an exception.
(ns proj.activity
(:import
(myjava Activity)
)
(:gen-class
:name "proj.activity.MyActivity"
:extends myjava.Activity
:exposes-methods {mymethod supermymethod}
))
(defn -mymethod [this]
(.supermymethod this) // ★ crashes here
(println "hello")
)
Here's a stacktrace.
Exception in thread "main" java.lang.NoClassDefFoundError: myjava/Preference
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at clojure.lang.Reflector.getMethods(Reflector.java:373)
at clojure.lang.Reflector.invokeNoArgInstanceMember(Reflector.java:311)
at proj.activity$_mymethod.invoke(activity.clj:12)
at proj.activity.MyActivity.mymethod(Unknown Source)
at proj.core$_main.doInvoke(core.clj:9)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at clojure.lang.AFn.applyToHelper(AFn.java:152)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at proj.core.main(Unknown Source)
Caused by: java.lang.ClassNotFoundException: myjava.Preference
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
Do I have to always use type hints on Android to prevent the problem?
Or should Clojure handle this situation?
The source code to reproduce this problem is at
https://github.com/anolivetree/clojure-genclass-method-invoke
Thanks
--
Hiroshi Sakurai
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.