0

ClassCastExceptionが発生します

java.lang.ClassCastException: java.lang.String cannot be cast to com.mcruiseon.common.contracts.IRegistrationResponse
    at com.mcruiseon.common.message.response.RegistrationResponse.getRegistrationResponse(RegistrationResponse.java:43)
    at com.mcruiseon.carpool4all.RegistrationService.post(RegistrationService.java:81)

ジャージーベースのサービスコード

@POST
@Path ("Request")
@Consumes({ MediaType.APPLICATION_JSON })
public Response post(JAXBElement<ClientIdentityConcrete> element) {
    RegistrationRequest request = new RegistrationRequest((ClientIdentityConcrete)(element.getValue()));
    RegistrationResponse response ;
    try {
        clientSession = new ClientSession(God.mCruiseOnServer) ;
    } catch (InvalidServerDNSorIPException e) {
        e.printStackTrace();
        return Response.serverError().build() ;
    }
    sessionKey = sessionManager.setClientSession(clientSession) ;
    clientSession.setSessionKey(sessionKey) ;

    clientSession.getSendQueue().sendRequest(request) ;
    try {
        response = (RegistrationResponse)clientSession.waitAndGetResponse(request) ;
    } catch (WaitedLongEnoughException e) {
        return Response.serverError().build() ;
    } catch (UnableToResolveResponseException e) {
        return Response.serverError().build() ;
    }

// Getting Exception in line below
    return Response.ok(response.getRegistrationResponse()).build();
}

サポートコード

public IRegistrationResponse getRegistrationResponse() {
        return ((IRegistrationResponse) super.getMessage());
    }

public interface IRegistrationResponse {
    public String getIdentityHash() ;
    public String getSessionKey() ;
}
4

1 に答える 1

0

サーバーが文字列を返していました。最新のjarファイルを使用してサーバーをアップロードするのを忘れました。それを行うと、ClassCastExceptionが消えました。

于 2012-10-24T03:59:36.397 に答える