I’m using Android 2.3.3 and Google APIs for developing a Map application.
The problem is in the below code:
GoogleHeaders headers = new GoogleHeaders();
headers.setApplicationName("My Sample Google App on Maps");
request.setHeaders(headers);
It shoots with the below error,
E/AndroidRuntime(382): FATAL EXCEPTION: main
E/AndroidRuntime(382): java.lang.IllegalAccessError: tried to access field com.google.api.client.googleapis.GoogleHeaders.userAgent from class com.google.api.client.googleapis.GoogleHeaders
E/AndroidRuntime(382): at com.google.api.client.googleapis.GoogleHeaders.setApplicationName(GoogleHeaders.java:129)
E/AndroidRuntime(382): at com.example.main.MapActivity$2.initialize(MapCallActivity.java:292)
E/AndroidRuntime(382): at com.google.api.client.http.HttpRequestFactory.buildRequest(HttpRequestFactory.java:91)
E/AndroidRuntime(382): at com.google.api.client.http.HttpRequestFactory.buildGetRequest(HttpRequestFactory.java:120)
E/AndroidRuntime(382): at com.example.main.MapActivity.MyMethod(MapCallActivity.java:248)
E/AndroidRuntime(382): at com.example.main.MapActivity.myMethod2(MapCallActivity.java:172)
E/AndroidRuntime(382): at com.example.main.MapActivity.onCreate(MapCallActivity.java:108)
E/AndroidRuntime(382): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(382): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
E/AndroidRuntime(382): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
E/AndroidRuntime(382): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(382): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
E/AndroidRuntime(382): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(382): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(382): at android.app.ActivityThread.main(ActivityThread.java:3683)
E/AndroidRuntime(382): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(382): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(382): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime(382): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime(382): at dalvik.system.NativeStart.main(Native Method)
Please explain me as I’m stuck and not able to move beyond this.
Used APIs:
google-api-client-googleapis-1.4.1-beta.jar
google-http-client-1.8.3-beta.jar
google-http-client-android2-1.8.3-beta.jar
google-oauth-client-1.8.0-beta.jar
Help would be appreciated!
I got the solution myself. Problem was with the Googleapis-1.4.1-beta.jar import that was the culprit for which the compiler wasn’t able to change data due to access restriction inside. And it was creating issues in GoogleHeaders.java.
It sets the userAgent variable via setApplicationName method that required access for the compiler. However, this is now modified as below.
Following is the new code for GoogleHeaders. Hope it helps for all such users.
Remove GoogleHeaders usage in full and it would run smoothly as a knife.
Cheers!