2

执行添加时,我在 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;
    }
}
4

1 回答 1

1

您的问题在于适配器的返回类型。由于您要返回 aint它正在尝试将其转换为 astring并且那是它失败的时候,因此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);
    }
}
于 2015-05-01T14:09:09.910 回答