连接谷歌日历出错



我正在尝试使用Oauth 2.0连接到谷歌日历。两天前工作正常,但现在抛出一个异常:"Caused by: java.lang.NoSuchMethodError: com.google.api.client.util.Strings.isNullOrEmpty(Ljava/lang/String;)Z".

我使用google-api-java-client-1.14.1。(我的库中有"google-http-client-1.14.1-beta.jar")。

问题只发生在部署版本,当我在本地机器上运行应用程序时一切正常。

代码:

public GoogleCredential conexion(String email, String scope) { 
    GoogleCredential credential =null;
    try{
        // Build service account credential.
        credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
        .setJsonFactory(JSON_FACTORY)
        .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
        .setServiceAccountScopes(scope)
        .setServiceAccountPrivateKeyFromP12File(new File(file))
        .setServiceAccountUser(email)
        .build();
    }
    catch(Exception e){
        e.printStackTrace();
    }

return credential;
}

public int function(){
    GoogleCredential sa = serviceAc.conexion("user@mail.com",CalendarScopes.CALENDAR);
    Calendar service = new Calendar(new NetHttpTransport(), new JacksonFactory(), sa);//   here throw the exception
.
.
.
}

根据java.lang.NoSuchMethodError,您试图调用在编译时类路径中可用的方法,并且在运行时类路径中不再可用检查此答案

所以,对于方法没有这样的错误(实际上你应该在这里发布完整的错误)这个方法在运行时不支持了所以你所要做的就是搜索这个方法和它支持的新类你会在新的Jar

中找到

最新更新