IBM Mobilefirst 7.0-Java Adapter无法在服务器端执行

时间:2015-05-01 13:39:53

标签: java ibm-mobilefirst mobilefirst-adapters

执行添加时,我在MobileFirst Java Adapter上获得以下内容 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;
    }
}

1 个答案:

答案 0 :(得分:1)

您的问题在于适配器的返回类型。由于您要返回int,因此它会尝试将其转换为string,而当它失败时就会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 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);
    }
}