I am getting a “No matching ctor found” error while trying to populate a Java class from Clojure.
I want to populate this class from Clojure.
import java.util.Date;
public class Account {
Account() { acct_num = 0;
trans_type = 'U';
trans_amt = 0.00;
cur_bal = 0.00;
last_update = null;
}
public int acct_num = 0;
public char trans_type;
public double trans_amt = 0.00;
public double cur_bal = 0.00;
public Date last_update;
}
I can import the class:
ba2-app=> (ns ba2-app (:import Account))
Account
but when I go to populate it, I get this error:
ba2-app=> (:use java.util.Date)
nil
ba2-app=> (Account. 1000 \C 100.00 0.00 (java.util.Date. "12/21/2011"))
java.lang.IllegalArgumentException: No matching ctor found for class Account (NO_SOURCE_FILE:9)
I followed these suggestions to get the Java class built in with my Clojure code. The suggestions which were very helpful, because I can now build the Java class.
Any pointers or suggestions would be helpful. I know the class members should be private, but this is to test out a larger project.
Make the constructor public with the public access modifier. Also your constructor doesn’t accept any args, but just sets a bunch of members to some values. So you can now actually only call it like:
(Account.)(if it were public).When you want to use a constructor like this:
(Account. 1000 \C 100.00 0.00 (java.util.Date. "12/21/2011"))you’ll have to add a constructor that accepts these types of arguments: