Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Visual J# / March 2004

Tip: Looking for answers? Try searching our database.

System.InvalidOperationException

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Reshma - 17 Mar 2004 05:01 GMT
hello
I am getting System.InvalidOperationException while trying to search an object in and ArrayList object. In the following  code i am getting System.InvalidOperationException in the lin
                                    int myIndex = myList.BinarySearch(myObject)

import System .*
import System.Collections .*

public class SamplesArrayLis

    public static void main(String[] args
   
        // Creates and initializes a new ArrayList
        ArrayList myAL = new ArrayList()
        for (int i = 0; i <= 4; i++
       
            myAL.Add(new Integer((i * 2)))
       
        // Locates a specific object that does not exist in the ArrayList
        Object myObjectOdd = new Integer(3)
        FindMyObject(myAL, myObjectOdd)
    } //Mai

    public static void FindMyObject(ArrayList myList, Object myObject
   
        int myIndex = myList.BinarySearch(myObject)
        if (myIndex < 0)  
            Console.WriteLine("The object to search for ({0}) is not found. The next larger object is at index {1}.", myObject, System.Convert.ToString(~myIndex))
       
        else  
            Console.WriteLine("The object to search for ({0}) is at index {1}.", myObject, System.Convert.ToString(myIndex))
       
    } //FindMyObjec
} //SamplesArrayList

Can any one help me out
Thanks
Lars-Inge T?nnessen - 17 Mar 2004 12:47 GMT
Looks like the Java types does not implement IComparable. Please use .net
types or a Java list collection. It works with the .net System.String().

import System .* ;
import System.Collections .* ;
public class SamplesArrayList
{
   public void FindMyObject(ArrayList myList, Object myObject)
   {
       int myIndex = myList.BinarySearch(new System.String(""+myObject));
       if (myIndex < 0)
       {
           Console.WriteLine("The object to search for ({0}) is not found.
The next larger object is at index {1}.", myObject,
System.Convert.ToString(~myIndex));
       }
       else
       {
           Console.WriteLine("The object to search for ({0}) is at index
{1}.", myObject,                     System.Convert.ToString(myIndex));
       }
   } //FindMyObject

   public SamplesArrayList()
   {
       // Creates and initializes a new ArrayList.
       ArrayList myAL = new ArrayList();
       for (int i = 0; i <= 4; i++)
       {
           myAL.Add(new System.String(""+(i * 2)));
       }

       // Locates a specific object that does not exist in the ArrayList.
       Object myObjectOdd = new System.String(""+3);
       FindMyObject(myAL, myObjectOdd);
   }

   public static void main(String[] args)
   {
       new SamplesArrayList();
   } //Main
} //SamplesArrayList

Lars-Inge T?nnessen
www.larsinge.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.