Bug 12649 - Java.Lang.Locale.Default.ToLanguageTag() throws an exception
Summary: Java.Lang.Locale.Default.ToLanguageTag() throws an exception
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.7.x
Hardware: Macintosh Mac OS
: High normal
Target Milestone: ---
Assignee: dean.ellis
Depends on:
Reported: 2013-06-12 04:47 UTC by Paul Johnson
Modified: 2017-07-03 21:34 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Paul Johnson 2013-06-12 04:47:27 UTC
When trying to get the default language for a device using Java.Lang.Locale.Default.ToLanguageTag(), the exception "Java.Lang.NoSuchMethodError" is thrown with the following throwback

no method with name='toLanguageTag' signature='()Ljava/lang/String;' in class Ljava/util/Locale;
at Android.Runtime.JNIEnv.GetMethodID (intptr,string,string) [0x00024] in /Users/builder/data/lanes/monodroid-mlion-master/65e93e7c/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:122
at Java.Util.Locale.ToLanguageTag () [0x00014] in /Users/builder/data/lanes/monodroid-mlion-master/65e93e7c/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Java.Util.Locale.cs:884
at ftrack2android.ftrack2..ctor (Android.Content.Context) [0x00095] in /Volumes/Developer/Developer/ftrack-2/android/ftrack2/ftrack2/Utils/Singleton.cs:33
at ftrack2android.SplashActivity.OnCreate (Android.OS.Bundle) [0x0000c] in /Volumes/Developer/Developer/ftrack-2/android/ftrack2/ftrack2/SplashActivity.cs:19
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-mlion-master/65e93e7c/source/monodroid/src/Mono.Android/platforms/android-10/src/generated/Android.App.Activity.cs:1553
at (wrapper dynamic-method) object.61589019-7946-46fb-9c1a-07139a793688 (intptr,intptr,intptr) <IL 0x00017, 0x00043>

  --- End of managed exception stack trace ---
java.lang.NoSuchMethodError: no method with name='toLanguageTag' signature='()Ljava/lang/String;' in class Ljava/util/Locale;
	at ftrack2android.SplashActivity.n_onCreate(Native Method)
	at ftrack2android.SplashActivity.onCreate(SplashActivity.java:28)
	at android.app.Activity.performCreate(Activity.java:5104)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
	at android.app.ActivityThread.access$600(ActivityThread.java:141)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:5041)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:511)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
	at dalvik.system.NativeStart.main(Native Method)

The code that generates this error is

string LanguageCode = Java.Util.Locale.Default.ToLanguageTag();

This compiles without an issue but dies on running
Comment 1 Atsushi Eno 2013-06-12 05:48:04 UTC
It is a bug on our release build environment: Lava.Lang.Locale.toLanguageTag() exists only after Java 1.7, and Android API, which is based on Java 6, does not support it. The binding should not expose that method that is very likely bound because our build environment runs Java7.

Thus, you cannot use that method.

We need to make sure to have a valid Java 6 environment to build XA.
Comment 2 Jonathan Pryor 2014-07-28 16:54:22 UTC
This will be fixed by using class-parse to generate api-19.xml.in.
Comment 3 MrSmith 2014-11-25 18:48:41 UTC
Issue is still happening. I tested it with Android API levels 16-19. Xamarin Studio is pointing to the Java SDK shown below

Product: Xamarin Studio
Version: 5.5.4 (build 15)
Android API Level: ALL
JDK: C:\Program Files (x86)\Java\jdk1.6.0_39

1. Create sample app
2. Include the following in you "Main.axml"

        android:id="@+id/editText1" />
Comment 4 Jonathan Pryor 2014-11-26 21:59:54 UTC
MrSmith: We never claimed it was fixed, so I don't understand why you mention that it's still happening.

That said, API-21 supports it: http://developer.android.com/reference/java/util/Locale.html#toLanguageTag()

Comment #2 remains the same: we need to stop using jar2xml to generate API descriptions, as it frequently lies. class-parse is designed to fix those issues.
Comment 5 Cody Beyer (MSFT) 2017-07-03 21:34:06 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Android. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.