Google Geocoding API返回illegalaccesserror

时间:2015-05-06 20:00:22

标签: java google-maps google-api geocoding

我当然希望你能提供帮助,我正在走向尽头。我昨天发布了这个问题,但很快就被投票了,因为我提到了我正在做的远程矩阵API,并且立即假设我在谷歌中启用了错误的API。我现在启用了比我需要的更多的API,并且仍然得到相同的IllegalAccessError:

May 06, 2015 12:48:16 PM com.google.maps.GeoApiContext setQueryRateLimit
INFO: Configuring rate limit at QPS: 10, minimum delay 50ms between requests
Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: tried     to access class com.squareup.okhttp.Dispatcher from class com.google.maps.GeoApiContext
at com.google.maps.GeoApiContext.setQueryRateLimit(GeoApiContext.java:224)
at com.google.maps.GeoApiContext.setQueryRateLimit(GeoApiContext.java:210)
at com.google.maps.GeoApiContext.<init>(GeoApiContext.java:56)
at budgetrouting.MapPane.<init>(MapPane.java:27)
at budgetrouting.BudgetRouting$1.run(BudgetRouting.java:19)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Process exited with exit code 0.

我的代码:

    GeoApiContext context = new GeoApiContext();
    context.setApiKey(APIKey);
    GeocodingResult[] results;
    try {
        results = GeocodingApi.geocode(context, "1600 Amphitheatre Parkway Mountain View, CA 94043").await();
    System.out.println(results[0].formattedAddress);
    } catch (Exception e) {
        e.printStackTrace();
    }

我已阅读有关此错误及其与谷歌API相关的每一条信息,但到目前为止,我还没有任何明确的答案。我认为这是一个错误而不是异常的事实意味着它可能与我的访问权限没有任何关系,特别是因为在我设置API密钥之前错误发生了。由于IllegalAccessError的定义指出&#34;如果类的定义已经不兼容地改变,则此错误只能在运行时发生,&#34;我将包含我的依赖项:

google-maps-services-0.1.1.jar
okhttp-1.2.1-jar-with-dependencies.jar

我已经检查了okhttp的完整性,并且错误中提到的类确实存在。我正在使用Oracle JDeveloper 12c。没有使用Maven型助手。

为了完整起见,这些是我启用的API:

BigQuery API
Debuglet Controller API
Directions API
Distance Matrix API
Elevation API
Geocoding API
Google Cloud Logging API
Google Cloud SQL
Google Cloud Storage
Google Cloud Storage JSON API
Google Maps Embed API
Google Maps Engine API
Time Zone API

有什么想法吗?谢谢!

2 个答案:

答案 0 :(得分:1)

我收到上述错误的原因是google-maps-services-0.1.1.jar需要okhttp 2.0.0,而不是okhttp-1.2.1-jar-with-dependencies.jar,以及其他一些的东西。这是因为没有使用类似Maven的应用程序。

答案 1 :(得分:0)

我使用这些库:

google-maps-services-0.1.1.jar -
okhttp-2.0.0.jar -
okio-1.11.0.jar -

示例代码:

<?php the_field('score_two'); ?>