On Oct 7, 2013, at 9:58 AM, nonameplum <
sliwins...@gmail.com> wrote:
>
> Example:
> <snip>
>
> public class MapMappper implements ResultSetMapper<List<Map<String, Object>>> {
>
> @Override
> public List<Map<String, Object>> map(int index, ResultSet r, StatementContext ctx) throws SQLException {
> System.out.println(r);
> Map<String, Object> obj = new HashMap<String, Object>();
> List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
>
> list.add(obj);
> return list;
> }
> }
>
> But I'm getting exceptions:
>
> Caused by: java.lang.NoSuchMethodException: sample.Controller$MapMappper.<init>()
> at java.lang.Class.getConstructor0(Class.java:2871)
> at java.lang.Class.newInstance(Class.java:402)
> ... 63 more
Are you sure the code you pasted here is exactly as it is in the source file? The most common cause for this specific problem is having your mapper as a non-static nested class, e.g.
public class MyDao {
public class MyMapper { … }
}
The problem is that in Java a inner class (a non-static nested class) has access to members of the enclosing object. To allow this access, the inner class has a hidden reference to the outer class, something like:
public class MyDao {
public class MyMapper {
private final MyDao outerReference;
public MyMapper(MyDao outerReference) { this.outerReference = outerReference; }
}
}
JDBI doesn't understand this "hidden" constructor parameter, and attempts to access a constructor with no parameters (the "sample.Controller$MapMappper.<init>()" bit), which does not exist.
TL;DR version: make your mapper static, or show us the actual code with more context.