2

I'm getting the following on my MobileFirst Java Adapter when performing an addition Error 500: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

@Path("/calc")
public class Calculator {
    @Context
    HttpServletRequest request;
    //Define the server api to be able to perform server operations
    WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
    @GET
    @Path("/addTwoIntegers/{first}/{second}")
    public int addTwoIntegers(@PathParam("first") String first, @PathParam("second") String second){
        int a=Integer.parseInt(first);
        int b=Integer.parseInt(second);
        int c=a+b;
       return c;
    }
}
Yoel Nunez
  • 2,108
  • 1
  • 13
  • 19
  • If I am removing quotations it throws an error like, Multiple markers at this line - first cannot be resolved to a variable - second cannot be resolved to a variable – Vinod Kumar Marupu May 01 '15 at 14:01

1 Answers1

1

Your problem is with the return type of your adapter. Since you are returning an int it is trying to convert it to a string and that's when it's failing hence the Error 500: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Try updating your code as follow:

@Path("/calc")
public class Calculator {
    @Context
    HttpServletRequest request;
    //Define the server api to be able to perform server operations
    WLServerAPI api = WLServerAPIProvider.getWLServerAPI();
    @GET
    @Path("/addTwoIntegers/{first}/{second}")
    public String addTwoIntegers(@PathParam("first") String first, @PathParam("second") String second){
        int a=Integer.parseInt(first);
        int b=Integer.parseInt(second);
        int c=a+b;
       return Integer.toString(c);
    }
}
Yoel Nunez
  • 2,108
  • 1
  • 13
  • 19