0

I have this code:

GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
String msg = getString(R.string.common_google_play_services_update_text);
Log.e(TAG, msg);
Dialog errDlg = googleAPI.getErrorDialog(MyActivity.this, result, 1111, listener);

When this runs, the String common_google_play_services_update_text is correctly written to LogCat, but getErrorDialog() throws this Exception:

java.lang.NoSuchFieldError: No static field common_google_play_services_update_text of type I in class Lcom/google/android/gms/R$string; or its superclasses (declaration of 'com.google.android.gms.R$string' appears in /data/app/com.mygame-1/base.apk)

How can I fix this?

activity
  • 431
  • 1
  • 7
  • 9

1 Answers1

0

The error NoSuchFieldError means that the class doesn't have a field of a specified name. It is thrown if an application tries to access or modify a specified field of an object, and that object no longer has that field. Normally, this error is caught by the compiler and can only occur at run time if the definition of a class has incompatibly changed.

Also, maybe you've got old code that is referencing a field that no longer exists in the recompiled class files. You may check it here.

The solution is to clean out all the class files and compile everything from fresh.

Update: If you still get the same error after recompiling everything, then you're probably compiling against one version of an external library and using another at runtime.

What you need to do now is first identify the class that is causing the problem (it looks like you have done this already) and then run your application with the -verbose:class command line option. It will dump a lot of class loading information on your standard out and you'll be able to find out where the problematic class is exactly loaded from.

Hope this helps!

Community
  • 1
  • 1
abielita
  • 13,147
  • 2
  • 17
  • 59
  • When the code runs, the String common_google_play_services_update_text is correctly written to LogCat. So it has to be an error with getErrorDialog(). – activity Mar 03 '17 at 12:31