Bug 10882 - AddAll throws an exception
Summary: AddAll throws an exception
Status: RESOLVED FEATURE
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: 4.6.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2013-03-04 11:31 UTC by Paul Johnson
Modified: 2013-03-12 13:03 UTC (History)
1 user (show)

Tags:
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:
Status:
RESOLVED FEATURE

Description Paul Johnson 2013-03-04 11:31:24 UTC
The following code throws a NoSuchMethodError for addAll

private Dictionary<string, int> courseDetails;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            TextView courseResult = FindViewById<TextView>(Resource.Id.textCourse);
            Spinner courseTitle = FindViewById<Spinner>(Resource.Id.spinner1);
            List<string> courses = new List<string>();                                                                    
            courses.AddRange(new string[]
            {
                "Chemistry",
                "Physics",
                "Biology",
                "Maths",
                "German"
            });
            List<int> courseNumbers = new List<int>();
            courseNumbers.AddRange(new int[] {101, 202, 303, 404, 505});
            courseDetails = new Dictionary<string, int>();
            int m = 0;
            foreach (string s in courses)
                courseDetails.Add(s, courseNumbers [m++]);
            ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SelectDialogItem);
            adapter.AddAll(courseDetails.Keys); // exception thrown here
            
            courseTitle.Adapter = adapter;

            courseTitle.ItemSelected += (object sender, AdapterView.ItemSelectedEventArgs e) =>
            {
                int courseToUse = 0;
                if (courseDetails.TryGetValue(courseTitle.SelectedItem.ToString(), out courseToUse))
                    courseResult.Text = courseToUse.ToString();
                else
                    courseResult.Text = "Course not found";
            };
        }


Java.Lang.NoSuchMethodError: addAll
  at Android.Runtime.JNIEnv.GetMethodID (intptr,string,string) [0x00024] in /Users/builder/data/lanes/monodroid-lion-bigsplash/dc1a99d6/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:122
  at Android.Widget.ArrayAdapter.AddAll (System.Collections.ICollection) [0x00014] in /Users/builder/data/lanes/monodroid-lion-bigsplash/dc1a99d6/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.Widget.ArrayAdapter.cs:297
  at spinner.Activity1.OnCreate (Android.OS.Bundle) [0x000ff] in /Users/PFJ/Developer/spinner/spinner/MainActivity.cs:41
  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (intptr,intptr,intptr) [0x00010] in /Users/builder/data/lanes/monodroid-lion-bigsplash/dc1a99d6/source/monodroid/src/Mono.Android/platforms/android-15/src/generated/Android.App.Activity.cs:1859
  at at (wrapper dynamic-method) object.e4188efb-3bad-47a3-b542-7e935d5ce41e (intptr,intptr,intptr) <IL 0x00017, 0x00043>
  at 
  at --- End of managed exception stack trace ---
  at java.lang.NoSuchMethodError: addAll
  at 	at spinner.Activity1.n_onCreate(Native Method)
  at 	at spinner.Activity1.onCreate(Activity1.java:28)
  at 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
  at 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
  at 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
  at 	at android.app.ActivityThread.access$1500(ActivityThread.java:132)
  at 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
  at 	at android.os.Handler.dispatchMessage(Handler.java:99)
  at 	at android.os.Looper.loop(Looper.java:150)
  at 	at android.app.ActivityThread.main(ActivityThread.java:4277)
  at 	at java.lang.reflect.Method.invokeNative(Native Method)
  at 	at java.lang.reflect.Method.invoke(Method.java:507)
  at 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  at 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  at 	at dalvik.system.NativeStart.main(Native Method)
  at 

The code builds and deploys without an issue.
Comment 1 Atsushi Eno 2013-03-05 14:50:49 UTC
Aren't you setting minSdkVersion as < 11, while target framework as >= 11 ? You cannot set minSdkVersion < 11 and still expect ArrayAdapter.addAll() works there.

If that's not the case please attach your project so that we can examine the exact issue.
Comment 2 Paul Johnson 2013-03-12 12:33:15 UTC
Surely though if I set the minSdkVersion then that should be the one intellisense pics up on?

It looks as if you're right, I have the target and minSdk out of alignment. Set them both to API 15 things work fine.
Comment 3 Atsushi Eno 2013-03-12 13:03:12 UTC
It is not the minSdkVersion but the Target Framework which should be the one that determines those Reference assemblies. You are supposed to avoid using the 11>= only API when your app is running on <11 API. It is doable by using Android.OS.Build.VERSION.SdkInt:
http://androidapi.xamarin.com/index.aspx?link=P%3aAndroid.OS.Build.VERSION.SdkInt

This would give you some hints on how to check framework version at run time using the Build.Version above:
http://developer.android.com/training/basics/activity-lifecycle/starting.html#Create
("// Make sure we're running on Honeycomb or higher to use ActionBar APIs" line)