Getting index out of range in picker view

akkakk USMember ✭✭✭
Index out of range

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited October 11

    The error happens when you try to access an element in a collection, using a numeric index that exceeds the collection's boundaries, please post your code ,we can not help you without code .

  • akkakk USMember ✭✭✭
    Ok let me send the code
  • akkakk USMember ✭✭✭
    This is my code
  • ColeXColeX Member, Xamarin Team Xamurai

    Copy code and paste here instead of the screen shot .

    It's better to attach a basic sample project for reproducing the error.

  • akkakk USMember ✭✭✭
    Ok
  • akkakk USMember ✭✭✭
    try
    {
    if (isFromFiles)
    {
    Console.WriteLine(PlusPortals.plusPortals().student.ClassesLinksFolderInfo.Length);
    if (row == 0)
    {
    return "Class Folder";
    }
    else
    {
    return parent.Target.isClassLinks
    ? PlusPortals.plusPortals().student.ClassesLinksFolderInfo[(int)row - 1].LabelTagDescription
    : PlusPortals.plusPortals().student.ClassesAllFolderInfo[(int)row - 1].LabelTagDescription;
    }
    }
    else
    {
    string meetingTime = "";
    string displayName = "";
    string courseName = "";
    string sectionName = "";
    Console.WriteLine(ClassesDetails.classSecions.Length);
    //MAPI-120
    if (ClassesDetails.classSecions != null)
    {
    if (MainTabViewController.MeetingTimeDefined() != 0)
    {
    if (ClassesDetails.classSecions[(int)row].MeetingTime != null)
    {
    meetingTime = ClassesDetails.classSecions[(int)row].MeetingTime.ToString();
    }
    }

    if (string.IsNullOrEmpty(ClassesDetails.classSecions[(int)row].DisplayAsForPSName))
    {
    if (!string.IsNullOrEmpty(ClassesDetails.classSecions[(int)row].CourseName))
    {
    courseName = ClassesDetails.classSecions[(int)row].CourseName;
    }
    if (!string.IsNullOrEmpty(ClassesDetails.classSecions[(int)row].CourseSection))
    {
    sectionName = ClassesDetails.classSecions[(int)row].CourseSection;
    }


    /*if (ClassesDetails.classSecions[(int)row].CourseName != null &&
    !ClassesDetails.classSecions[(int)row].CourseName.Equals(""))
    {
    courseName = ClassesDetails.classSecions[(int)row].CourseName;
    }
    if (ClassesDetails.classSecions[(int)row].CourseSection != null &&
    !ClassesDetails.classSecions[(int)row].CourseSection.Equals(""))
    {
    sectionName = ClassesDetails.classSecions[(int)row].CourseSection;
    }*/
    displayName = courseName + " " + sectionName;

    }
    else
    {
    displayName = ClassesDetails.classSecions[(int)row].DisplayAsForPSName;
    }
    }
    string pickerString = "";
    if (meetingTime.Equals("") || courseName.Equals("") || sectionName.Equals(""))
    {
    pickerString = string.Format("{0}", displayName);
    }
    else
    {
    pickerString = string.Format("{0} ({1}) {2}", courseName, meetingTime, sectionName);
    }

    return pickerString;
    }
    }
    catch (Exception ex)
    {
    AppDelegate.LogException(ex);
    return "";
    }
  • ColeXColeX Member, Xamarin Team Xamurai

    Could you figure out which line causes the exception?

Sign In or Register to comment.