I am new to Java and am trying to get a sample working for Rapidoid. I have the code exactly has is in the example but when I run it, I get a null pointer exception on Startup. I have tried a few variations that do work, the thing is this is on Startup.
The issue is with the parameter inside the lambda which is as stated in the various examples.
The uncommented line is as it is in the sample.
This is using java 1.8 on Windows 10 and Rapidoid is 5.5.5
import org.rapidoid.http.Req;
import org.rapidoid.setup.On;
public class RapidoidHttpFast
{
public static void main(String[] args)
{
// On GET /size return the length of the "msg" parameter
//On.get("/size").json( "dog" ); // Works
//On.get("/size").json( () -> "dog" ); // Works
//On.get("/size").json( (Integer i) -> i ); // Fails
On.get("/size").json( (String msg) -> msg.length() ); // Fails
//On.get("/size").json( (Req req) -> req.path() ); // Works
}
}
Here is the stack trace when it fails, when it works I get results returned to the web browser.
INFO | 23/Aug/2019 17:40:35:846 | main | org.rapidoid.config.RapidoidInitializer | Starting Rapidoid v5.5.5, built on 2018-05-27 15:45 UTC
INFO | 23/Aug/2019 17:40:35:848 | main | org.rapidoid.config.RapidoidInitializer | System info | os = Windows 10 | java = 1.8.0_211 | process = 31568@LAPTOP-6OO0M88U | max memory = 247 MB | dir = C:\Root\learning\java\rapidoid
INFO | 23/Aug/2019 17:40:36:022 | main | org.rapidoid.env.Environment | No profiles were specified, activating 'default' profile
INFO | 23/Aug/2019 17:40:36:029 | main | org.rapidoid.env.Environment | No production/dev/test mode was configured, inferring mode | mode = DEV
INFO | 23/Aug/2019 17:40:36:030 | main | org.rapidoid.env.Environment | Initialized environment | mode = DEV | profiles = [default, dev]
INFO | 23/Aug/2019 17:40:36:129 | main | org.rapidoid.config.ConfigImpl | Loaded configuration | namespace = config | files = [1m[built-in-config.yml, built-in-config-default.yml, built-in-config-dev.yml][0m
Exception in thread "main" java.lang.NullPointerException
at org.rapidoid.cls.Cls.getMethodParameterNames(Cls.java:1199)
at org.rapidoid.cls.Cls.getLambdaParameterNames(Cls.java:1248)
at org.rapidoid.http.handler.lambda.NParamMethodHandler.<init>(NParamMethodHandler.java:58)
at org.rapidoid.http.handler.lambda.NParamLambdaHandler.<init>(NParamLambdaHandler.java:37)
at org.rapidoid.http.handler.lambda.OneParamLambdaHandler.<init>(OneParamLambdaHandler.java:41)
at org.rapidoid.setup.HttpHandlers.from(HttpHandlers.java:70)
at org.rapidoid.setup.HttpHandlers.register(HttpHandlers.java:126)
at org.rapidoid.setup.OnRoute.json(OnRoute.java:202)
at RapidoidHttpFast.main(RapidoidHttpFast.java:17)
I am not using any external config file, it is using the default one. I am not sure if there are other settings required.
It could be something obvious but as stated I am new to Java and still feeling my way around.
Thanks for any help.