简体   繁体   中英

Android Google Maps API v2 - NoSuchFieldError

I am working on a project using Google Maps v2 for Android and I am getting a NoSuchFieldError while instantiating the Google map fragment on a rooted HTC Desire HD.

Afaik, the issue should not be caused by Google Play Services not being installed on the device (event though they are and other applications using Google Maps v2 are working).

I have tried making a check to see if Google Play Services library is installed on the device (by calling GooglePlayServicesUtil.isGooglePlayServicesAvailable ) prior to setting the Activity 's content view.

Furthermore, the application runs on other Android phones and the map fragment is successfully inflated.

At the moment I suspect that this issue is caused by my Android project setup in Eclipse, as the Google Play Services library project seems not to be included along with my project during packaging or deployment.

Has anyone had and solved this issue with Google Maps working only on some devices and throwing a NoSuchFieldError exception on others? If so, what can I do to solve this?

If you need more information such as project setup and/or code, please leave a comment.

Thank you!

This is the stack trace report from ACRA in JSON format:

{ CUSTOM_DATA: '', STACK_TRACE: 'java.lang.NoSuchFieldError: com.google.android.gms.R$string.common_google_play_services_unsupported_text\\n\\tat com.google.android.gms.common.GooglePlayServicesUtil.b(Unknown Source)\\n\\tat com.google.android.gms.internal.bb.a(Unknown Source)\\n\\tat com.google.android.gms.internal.bb.onCreateView(Unknown Source)\\n\\tat com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)\\n\\tat android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)\\n\\tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)\\n\\tat android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)\\n\\tat android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)\\n\\tat android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)\\n\\tat android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)\\n\\tat android.view.LayoutInflater.rInflate(LayoutInflater.java)\\n\\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\\n\\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\\n\\tat android.view.LayoutInflater.inflate(LayoutInflater.java)\\n\\tat com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)\\n\\tat android.app.Activity.setContentView(Activity.java)\\n\\tat ro.myapp.app.activities.MapActivity.onCreate(MapActivity.java:62)\\n\\tat android.app.Activity.performCreate(Activity.java)\\n\\tat android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)\\n\\tat android.app.ActivityThread.performLaunchActivity(ActivityThread.java)\\n\\tat android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)\\n\\tat android.app.ActivityThread.access$600(ActivityThread.java)\\n\\tat android.app.ActivityThread$H.handleMessage(ActivityThread.java)\\n\\tat android.os.Handler.dispatchMessage(Handler.java)\\n\\tat android.os.Looper.loop(Looper.java)\\n\\tat android.app.ActivityThread.main(ActivityThread.java)\\n\\tat java.lang.reflect.Method.invokeNative(Native Method)\\n\\tat java.lang.reflect.Method.invoke(Method.java)\\n\\tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)\\n\\tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java)\\n\\tat dalvik.system.NativeStart.main(Native Method)\\n', PHONE_MODEL: 'HTC Desire HD', ANDROID_VERSION: '4.0.4' }

This is my onCreate method throwing the exception:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    checkForPlayServices();

    setContentView(R.layout.activity_map);
    mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
    map = mapFragment.getMap();
    map.setMyLocationEnabled(true);
    map.setInfoWindowAdapter(this);
    map.setOnInfoWindowClickListener(this);
}

Contents of activity_map.xml layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity" >

    <ro.myapp.app.views.actionbar.ActionbarMap
        android:id="@+id/actionBar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/myapp_actionbar_height" />

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/actionBar"
        class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout> 
java.lang.NoSuchFieldError: com.google.android.gms.R$string.common_google_play_services_unsupported_text

says exactly what is the problem.

In values/strings.xml there is no

<string name="common_google_play_services_unsupported_text">...</string>

defined.

I see this value defined in my google-play-services_lib/res, so you may want to check if you correctly added this library project to your workspace. Seems like you have forgot to update strings.xml when updating library.

好的,所以我改变了我的答案我发现有一种方法可以找出是否有任何覆盖你的库....你正在某处使用位置对象所以添加这些代码并在运行其中一个设备时调试它。 ....位置对象应该在您的位置监听器中。

 location.getClass().getProtectionDomain().getCodeSource().getLocation() ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM