Converting an array to a Linked list.

I'm writing somewhat of a card game. One of the functions I'm supposed to have is the cut function. I'm supposed to split the deck into two and place the bottom half on top of the top half. My card objects are stored in Nodes in a programmer defined linked list. I believe I successfully converted the linked list into two array (top and bottom) but I am having problems with converting these back to LinkedList (atleast thats where I think my problem is) This is the code i had so far:
     public void cut()
          if (isEmpty())
               throw new DeckException("Deck of Cards");
          else
               int pivot = (int)(Math.random()*numCards);
               Node top[] = new Node[pivot];
               Node bottom[] = new Node[numCards-pivot];
               Node traveller = front;
                        //Convert the linkedList into two arrays
               for(int i = 0; i < numCards; i++)
                    if(i < pivot)
                         top[i] = traveller;
                         traveller = traveller.getNext();
                    else
                         bottom[i-pivot] = traveller;
                         traveller = traveller.getNext();
                        //Convert the two arrays back to a LinkedList, where bottom is put in the front of the list and top is put on the end
               traveller = front;
               for(int i = 0; i < numCards; i++)
                    if(i < bottom.length)
                                        //reference comment 1
                         traveller.setNext(bottom);
                         traveller = traveller.getNext();
                    else
//reference comment 2
                         traveller.setNext(top[i-bottom.length]);
                         traveller = traveller.getNext();
     }I'm not really sure what I'm doing wrong but when i play around with the code I get alot of ArrayOutOfBounds error around the comment above marked as reference comment 1 and 2
Can someone please give me guidance as to what I'm doing wrong? I feel as If I've reached a block i can't get past.
EDIT: the variable numCards above should have the value 52
Edited by: 806583 on Oct 31, 2010 11:12 PM

My Node class is public. It does not implement the List Interface. This is my Node class:package project3;
public class Node
  private Card data; //a reference to an object of type T
  private Node next; //the address of the next node in the list
   * default constructor - initializes data and next to null
  public Node()
       data = null;
       next = null;
   * parameterized constructor - initializes data to the user
   * specified value; next is set to null
   * @param newItem the value to be stored in the node
  public Node(Card newItem)
    data = newItem;
    next = null;
   * parameterized constructor - initializes data and next to user
   * specified values
   * @param newItem the object reference to be stored in the node
   * @param nextItem the reference to the next node in the list
  public Node(Card newItem, Node nextItem)
    data = newItem;
    next = nextItem;
   * setItem - stores a new value in data
   * @param newItem the object reference to be stored in the node
  public void setItem(Card newItem)
    data = newItem;
   * setNext - stores a new value in next
   * @param nextItem the reference to be stored in next
  public void setNext(Node nextItem)
    next = nextItem;
   * getItem - returns the reference stored in data
   * @return a reference to the data stored in the node
  public Card getItem()
    return data;
   * getNext - returns the reference stored in next
   * @return the reference stored in next
  public Node getNext()
    return next;
}

Similar Messages

  • Is there an example vi for converting an array of boolean to list an array of Int based on a selected T/F state?

    I would like to use arrays to minimize code.
    I am trying to generate an array of int base on an array of boolean randomly selected.

    You can try using 'Boolean to 0,1.vi', found in the Boolean palette: this vi converts a scalar, array or cluster of booleans to a scalar, array or cluster of word (I16 integers).
    To use it, simply wire an array of booleans (indicator) to its left, and an array of integers (control) to its right et voilà.
    Roberto
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Linked List

    Hello
    I got a problem trying to store arrays in a linked list. i need to store 3 numbers in the array(eg a[0], a[1], a[2]) in a link list and another 3 in another and so on. (dnt have to use arrays but i used it to store the 3 number in one linked list)
    when i use arrays to store em it says cants store int cos my links list stores objects! i cant convert the numbers to object cos then i need to search for the particular set of numbers from the link list.
    if some one could help me by explaing wat i could do i will be gratefull
    thanks!!!

    Yes, as danperkins suggests you can insert groups of three int[] into your list ...and then as your search through the list, pull each group of three ints back out of each list node and analyze them on the spot to see if they are equal.
    What I was suggesting is to encapsulate your three ints into a class that becomes an entity called, say ...ThreeInts. Then, you could add the functionality inside this object to determine if it was equal to another object of the same type. Same thing as danperkins suggestion, except one requires external routines to process each node and the other (mine) uses an object that knows how to process itself.
    This is a fundamental facet of OOP programming ...representing data in objects that know how to store their values ...know how to express themselves ...know how to order and compare themselves ...etc, etc, etc.
    The way I see it, I have given you the structures required to complete your task ...you just have to operate on them and incorporate them into your code. If you don't see how to do this, then I don't really know what else to suggest ...sorry.
    semi - psuedocode created from what you have so far might be as follows.
    // Insert ThreeInts objects into linked list...
    // Where array is original array of 120 ints...
    for (int k=0, k<array.length; k++) {
      if( (k%3)==0 && k!=0 ) {
        list.add(new ThreeInts(array[k-2],array[k-1],array[k]);
    // Search for specific ThreeInts objects in linked list...
    // i.e. "find an object in the list equal to the object ThreeInts(3,5,8)"
    ThreeInts found = searchList( new ThreeInts(3,5,8) );Basically, the ThreeInts object is a class that knows how to hold three integers ...knows how to give these three integers back to you ...and most importantly knows how to compare itself to another ThreeInts object and say "yes, I am the same" ...or "No, I am not the same". That is what MyCuteLittleClass will do ...you just have to change its name to ThreeInts. Beyond this, I don't know what else to say.

  • Constructing a linked list from an array of integers

    How do I create a linked list from an array of 28 integers in a constructor? The array of integers can be of any value that we desire. However we must use that array to test and debug methods such as getFirst(), getLast(), etc...
    I also have a method int getPosition(int position) where its suppose to return an element at the specified position. However, I get an error that says cannot find symbol: variable data or method next()
    public int getPosition(int position){
         LinkedListIterator iter=new LinkedListIterator();
         Node previous=null;
         Node current=first;
         if(position==0)
         return current.data;
         while(iter.hasMore()){
         iter.next();
         if(position==1)
         return iter.data;
         iter.next();
         if(position==2)
         return iter.data;
         iter.next();
         if(position==3)
         return iter.data;
         iter.next();
         if(position==4)
         return iter.data;
         iter.next();
         if(position==5)
         return iter.data;
         iter.next();
         if(position==6)
         return iter.data;
         iter.next();
         if(position==7)
         return iter.data;
         iter.next();
         if(position==8)
         return iter.data;
         iter.next();
         if(position==9)
         return iter.data;
         iter.next();
         if(position==10)
         return iter.data;
         iter.next();
         if(position==11)
         return iter.data;
         iter.next();
         if(position==12)
         return iter.data;
         iter.next();
         if(position==13)
         return iter.data;
         iter.next();
         if(position==14)
         return iter.data;
         iter.next();
         if(position==15)
         return iter.data;
         iter.next();
         if(position==16)
         return iter.data;
         iter.next();
         if(position==17)
         return iter.data;
         iter.next();
         if(position==18)
         return iter.data;
         iter.next();
         if(position==19)
         return iter.data;
         iter.next();
         if(position==20)
         return iter.data;
         iter.next();
         if(position==21)
         return iter.data;
         iter.next();
         if(position==22)
         return iter.data;
         iter.next();
         if(position==23)
         return iter.data;
         iter.next();
         if(position==24)
         return iter.data;
         iter.next();
         if(position==25)
         return iter.data;
         iter.next();
         if(position==26)
         return iter.data;
         iter.next();
         if(position==27)
         return iter.data;
         iter.next();
         if(position==28)
         return iter.data;
         if(position>28 || position<0)
         throw new NoSuchElementException();
         }

    How do I create a linked list from an array of 28 integers
    in a constructor? In a LinkedList constructor? If you check the LinkedList class (google 'java LinkedList'), there is no constructor that accepts an integer array.
    In a constructor of your own class? Use a for loop to step through your array and use the LinkedList add() method to add the elements of your array to your LinkedList.
    I get an error that
    says cannot find symbol: variable data or method
    next()If you look at the LinkedListIterator class (google, wait for it...."java LinkedListIterator"), you will see there is no next() method. Instead, you typically do the following to get an iterator:
    LinkedList myLL = new LinkedList();
    Iterator iter = myLL.iterator();
    The Iterator class has a next() method.

  • Re: array of references to linked lists

    Hi, im having a little problem seeing the wood from the tree...shouldnt be too hard for a fresh pair of eyes...ive been trying for a while now(read ages !!).
    I have an array which will be populated with seperate linked lists (StudentList class) which are populated from a console interface (prompt).
    It seems to work fine, however .. each list entered will overwrite the last by adding itself to it. eg :
    list 1 is added : adam 998 albert 999
    list 2 is added : john 123 jill 666
    lists[0].print() : jill 666 john 123 albert 999 adam 998
    lists[1].print() : jill 666 john 123 albert 999 adam 998
    it should give
    lists[0].print() : jill 666 john 123
    lists[1].print() : albert 999 adam 998
    the code is below,
    cheers for ANY help,
    ta.
    import java.io.*;
    import java.util.*;
    public class StudentId {
         public static void main(java.lang.String[] args) {
              StudentList[] lists = new StudentList[20];
              for (int i = 0; i < lists.length; i++) {
                   lists[i] = new StudentList();
              int n = 0;
              BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
              for(;;) {
                   System.out.print("Please enter a student record list> ");
                   try {
                        //StudentList list = new StudentList();
                        String line = in.readLine();
                        if (line.equals("quit")) {
                             break;
                        StringTokenizer tokenBag = new StringTokenizer (line," ");
                        while (tokenBag.hasMoreTokens()) {
                             try {
                                  String name = tokenBag.nextToken();
                                  String idString = tokenBag.nextToken();
                                  int id = Integer.parseInt(idString);
                                  lists[n].insert(name, id);
                             catch(Exception e) {
                                  System.out.println("Input error : " + e);
                   catch (Exception e) {
                        System.out.println("exception : " + e);
                   n += 1;
              for (int i=0; i<n; i++) {
                   System.out.println("element " + i);
                   lists.print();

    other class (Int node class is standard node class altered
    public class StudentList {
         private static IntNode head;
         private static int count;
         public StudentList() {
              head = null;
              count = 0;
         public boolean isEmpty() {
              if (count == 0) return true;
              else return false;
         public int size(){
              return count;
        public IntNode getHead() {
              return head;
         public void printHead() {
              System.out.println(head.getName() + " " + head.getId());
         public IntNode getTail() {
              IntNode cursor;
              for (cursor = head; cursor != null; cursor = cursor.getLink()) {
              return cursor;
         public void insert(String name, int id){
              head = new IntNode(name, id ,head);
              count++;
         public IntNode searchFor(String name) {
              IntNode cursor;
              cursor = head.listSearch(head, name);
              return cursor;
         public IntNode searchFor(int id) {
              IntNode cursor;
              cursor = head.listSearch(head, id);
              return cursor;
         public void print() {
              IntNode cursor = head;
              for (int i=0; i<count; i++) {
                   System.out.println(cursor.getName()+" "+cursor.getId());
                   cursor = cursor.getLink();
         public void insertListBefore(IntNode match, StudentList list) {
              IntNode preCursor = head.getPrevious(head, match);
              IntNode cursor;
              cursor = this.searchFor(match.getName());
              preCursor.setLink(list.getHead());
              list.getTail().setLink(cursor);
    }

  • Array of Linked List Help

    I am fairly new to Java, and Linked Lists. Can you tell me how I can fix my code? Why does my code print infinite "3" s. That is all I am trying to do is create a linked list and put that linked list into index 2 of the array. In the loop, I am setting up a whole bunch on null Node's, is it even possible to link all these nodes together in that same loop? If something does not make sense, I will try to elaborate. I will eventually impliment an insert method in the Node class, are there any pointers on how to implement it? What are the special cases I need to be looking for when implementing the insert method?
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package testlinkedlist;
    * @author Ben
    public class Main {
         * @param args the command line arguments
        public static Node l;
        public static Node p = new Node();
        public static Node Front;
        public static void main(String[] args) {
            Node[] anArray = new Node[4];
            for(int i = 0; i < 4; i++){
                anArray[i] = new Node();
                l = new Node(i);
                l.setLink(l);
            anArray[2] = l;         
            while(anArray[2] != null){
                System.out.println(anArray[2].dataInNode());
                anArray[2] = anArray[2].next;
    }

    l = new Node(i);
    l.setLink(l);The node l is created in line one, in line two a link is created from l to l. In other words here is the presence of your infinite loop which is magnified in the following piece of code:
    anArray[2] = l;         
    while(anArray[2] != null){
      System.out.println(anArray[2].dataInNode());
      anArray[2] = anArray[2].next;
    }Mel

  • Linked Lists with Arrays

    I am setting up a linked list of the following very simplified class:
    class LinkedList
         String Name=" ";
         double ID=0;
         static long next=0;
    }the main class is as follows:
    class Links
         public static void Display(LinkedList Link)
         /** A Display function that simply displays everything within the LinkedList class*/
         System.out.println("\nName: " + Link.Name +"\nID  #: " + Link.ID + "\nNext ID: " + Link.next);
         public static void main(String[] args)
              int MAX_LINKS=10;
              LinkedList[] Link=new LinkedList[MAX_LINKS];
              for (int i=0;i<MAX_LINKS;i++)
                   Link.ID=i;
                   Link[i].next++;
                   Display(Link[i]);
    everything compiles fine, but at runtime I recieve a
    Exception in thread "main" java.lang.NullPointerException
    at Links.Display(Links.java:6)
    at Links.main(Links.java:18)What am I doing wrong?
    Thanks in advance.

    public static void main(String[] args){
       int MAX_LINKS=10;
    // this tells the compiler that the Link array will hold
    //LinkedList objects, but doesn't actually create those objects...
       LinkedList[] Link=new LinkedList[MAX_LINKS];
       for (int i=0;i<MAX_LINKS;i++){
    //NEED TO ADD THIS LINE to create the objects:
          Link[ i ] = new LinkedList();
          Link[ i ].ID=i;
          Link[ i ].next++;
          Display(Link[ i ]);

  • Converting an array to a list using javascript

    There are several methods that return arrays, which we all know express cannot handle. The IDM faq metions you can use a script tag to manipulate array data, but gives no example. I like this method because some methods I encounter preface the object name with the object type, and the data needs to be cleaned before use. I always like little snippits that can be reused, so I'm sharing this one.
    Here is how to convert an array to a list, assuming the array is captured in "stupidarray":
        <split>
          <script>
            var myarray = env.get('stupidarray');
            // Code to manipulate the array
            outputarray = myarray.join(",")
            // Other code to manipulate the string before output
            // i.e. Stripping out the object type tags!
            // outputarray.replace(/User:/g,"");
          </script>
          <s>,</s>
        </split>

    there is a waveset util class provided for this, please check API
    --sFred                                                                                                                                                                                       

  • Need help on creating a linked list with array...

    I want to create a linked listed using array method. Any suggestion on how would I start it.
    thanks

    That means I want to implement linked list using an
    array.I believe you mean you want to implement list using an array. Linked list is a very different implementation of a list, which can be combined with arrays for a niche implementation of list, but I don't think this is what you're talking about.
    Do you mind if we ask why you don't want to use ArrayList? It does exactly what you specify, plus it will increase the size of the internal array as necessary to ensure it can store the required elements.
    If you really want to make your own, have a look at the source for ArrayList (in src.jar in your JDK installation folder) - it will answer any questions you have. If you don't understand any of the code, feel free to post the relevant code here and ask for clarification.

  • ObservableList - "Linked list" or "Dynamic array"?

    I always assumed ObservableList (or more precisely, its implementation that is used to store child nodes) to be a linked list. Well, is it? :)
    Thanks for reading!

    stepan wrote:
    Unfortunately, java.util.List is itself only an interface. What I'm concerned with is an actual implementation (i.e. data structure used).
    Let me clarify my motivation by formulating the question more specifically: When dealing with an instance of ObservableList obtained by calling Parent's getChildren() method, will the get(int) method run in O(1) or O(size())? The latter would suggest it really may be a linked list...Previous answers mine included doesn't help much after I re-read your actual question :).
    Barring an actual answer from the Source (One of the Oracle engineers) vs the Source (code.....) I found an answer to your question after digging around in the private packages for a bit. Children nodes to a Parent are initially created as an ArrayList. I suppose its possible that ArrayList could be replaced later by some other implementation of List during a Class's use at runtime (some corner use-case where LinkedList is favored for insertion speed) - but when they are born they are ArrayLists.
    The javafx.scene.Parent class creates children as a VetoableObservableList()..
    private final ObservableList children = new VetoableObservableList() {
    };The constructor for class com.sun.javafx.collections.VetoableObservableList
    public VetoableObservableList()
            super(new ArrayList());
        }

  • Alphabetizing a linked list, HELP!

    To all:
    Firstly, I'm not looking for someone to do my assignment for me. I just need a push in the right direction...
    I need to create a linked list that contains nodes of a single string (a first name), but that list needs to be alphabetized and that's where I am stuck.
    I can use an iterator method that will display a plain-old "make a new node the head" linked list with no problem. But I'm under the impression that an iterator method is also the way to go in alphabetizing this list (that is using an iterative method to determine the correct place to place a new node in the linked list). And I am having zero luck doing that.
    The iterator method looks something like this:
    // ---- MyList: DisplayList method ----
    void DisplayList()
    ListNode p;
    for (ResetIterator(); (p = Iterate()) != null; )
    p.DisplayNode();
    // ---- MyList: ResetIterator method ----
    void ResetIterator()
    current = head;
    // ---- MyList: Iterate method ----
    ListNode Iterate()
    if (current != null)
    current = current.next;
    return current;
    Can I use the same iterator method to both display the final linked list AND alphabetize my linked list or do I need to create a whole new iterator method, one for each?
    Please, someone give me a hint where to go with this. I've spent something like 15 hours so far trying to figure this thing out and I'm just stuck.
    Thanks so much,
    John
    [email protected]

    I'll try and point you in the right direction without being too explicit as you request.
    Is your "linked list" an instance of the Java class java.util.LinkedList or a class of your own?
    If it is the Java class, then check out some of the other types of Collections that provide built-in sorting. You should be able to easily convert from your List to another type of Collection and back again to implement the sorting. (hint: you can do this in two lines of code).
    If this is your own class and you want to code the sort yourself, implement something simple such as a bubble sort (should be easy to research on the web).
    Converting to an array, sorting that and converting back is another option.
    Good Luck.

  • Convert byte array to table of int

    [http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
    I'm pretty new with PL/SQL.
    I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
    The code converts byte array to table of int.
    The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
    The TSQL code is:
    CREATE FUNCTION dbo.GetTableVarchar(@Data image)
    RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
    Value Varchar(8000))
    AS
    BEGIN
    --First Test the data is of type Varchar.
    IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
    --Loop thru the list inserting each
    -- item into the variable table.
    DECLARE @Ptr int, @Length int,
    @VarcharLength smallint, @Value Varchar(8000)
    SELECT @Length = DataLength(@Data), @Ptr = 2
    WHILE(@Ptr<@Length)
    BEGIN
    --The first 2 bytes of each item is the length of the
    --varchar, a negative number designates a null value.
    SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
    SET @Ptr = @Ptr + 2
    IF(@VarcharLength<0)
    SET @Value = NULL
    ELSE
    BEGIN
    SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
    SET @Ptr = @Ptr + @VarcharLength
    END
    INSERT INTO @DataTable (Value) VALUES(@Value)
    END
    RETURN
    END
    It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
    The C# code is:
    public byte[] Convert2Bytes(int[] list)
    if (list == null || list.Length == 0)
    return new byte[0];
    byte[] data = new byte[list.Length * 4];
    int k = 0;
    for (int i = 0; i < list.Length; i++)
    byte[] intBytes = BitConverter.GetBytes(list);
    for (int j = intBytes.Length - 1; j >= 0; j--)
    data[k++] = intBytes[j];
    return data;
    I tryied to convert the TSQL code to PL/SQL and thats what I've got:
    FUNCTION GetTableInt(p_Data blob)
    RETURN t_array --t_array is table of int
    AS
    l_Ptr number;
    l_Length number;
    l_ID number;
    l_data t_array;
    BEGIN
         l_Length := dbms_lob.getlength(p_Data);
    l_Ptr := 1;
         WHILE(l_Ptr<=l_Length)
         loop
              l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
              IF(l_ID<-2147483646)THEN
                   IF(l_ID=-2147483648)THEN
                        l_ID := NULL;
                   ELSE
                        l_Ptr := l_Ptr + 4;
                        l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
                   END IF;
                   END IF;
    l_data(l_data.count) := l_ID;
              l_Ptr := l_Ptr + 4;
         END loop;
         RETURN l_data;
    END GetTableInt;
    This isn't work.
    This is the error:
    Error report:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    06502. 00000 - "PL/SQL: numeric or value error%s"
    I think the problem is in this line:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    but I don't know how to fix that.
    Thanks,
    MTs.

    I'd found the solution.
    I need to write:
    l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
    instead of:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works.

  • After Delete in Linked list...unable to display the linked list

    Hi...i know that there is an implementation of the class Linked Link but i am required to show how the linked list works in this case for my project...please help...
    Yes..I tried to delete some objects in a linked list but after that i am not able to display the objects that were already in the linked list properly and instead it throws an NullPointerException.
    Below shows the relevant coding for deleting and listing the linked list...
    public Node remove(Comparator comparer) throws Exception {
         boolean found = false;
         Node prevnode = head;          //the node before the nextnode
         Node deletedNode = null;     //node deleted...
         //get next node and apply removal criteria
         for(Node nextnode = head.getNextNode(); nextnode != null; nextnode = nextnode.getNextNode()) {
              if(comparer.equals(nextnode)) {
                   found = true;
                   //remove the next node from the list and return it
                   prevnode.setNextNode(nextnode.getNextNode());
                   nextnode.setNextNode(null);
                   deletedNode = nextnode;
                   count = count - 1;
                   break;
         if (found) return deletedNode;
         else throw new Exception ("Not found !!!");
    public Object[] list() {
         //code to gather information into object array
         Node node;
         Object[] nodes = new Object[count];
         node = head.getNextNode();
         for (int i=0; i<count; i++) {
              nodes[i] = node.getInformation();  // this is the line that cause runtime error after deleting...but before deleting, it works without problem.
              node = node.getNextNode();
         return nodes;
    }Please help me in figuring out what went wrong with that line...so far i really can't see any problem with it but it still throws a NullPointerException
    Thanks

    OK -- I've had a cup and my systems are coming back on line...
    The problem looks to be the way that you are handling the pointer to the previous node in your deletion code. Essentially, that is not getting incremented along with the nextNode -- it is always pointing to head. So when you find the node to delete then the line
       prevnode.setNextNode(nextnode.getNextNode());will set the nextNode for head to be null in certain situations (like if you are removing the tail, for instance).
    Then when you try to print out the list, the first call you make is
    node = head.getNextNode();Which has been set to null, so you get an NPE when you try to access the information.
    Nothing like my favorite alkaloid to help things along on a Monday morning...
    - N

  • How can I convert an array to image(8bit)

    I can convert an array(acquire from usb camera)to a picture,but not images(8 bit grayscale),how can I do it.many thanks!
    Attachments:
    array to image.vi ‏249 KB

    Sorry, this is the kind of thing that happens when you have been out for too long.
    Message Edité par chilly charly le 10-22-2006 11:09 AM
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    array%20to%20image[1].png ‏3 KB

  • How to convert an array collection instance to a complex object for interaction with webservice

    Hi there,
    I have a stubborn problem that I am trying to work out the best way to solve the problem.  I am interacting with a WebService via HTTPService calling a method called find(String name) and this returns me a List of ComplexObjects that contain general string and int params and also lists of other Complex Objects.  Now using the code:
    ArrayCollection newOriginalResultsArray = new ArrayCollection(event.result as Array)
    flex converts my complex objects results to an arraycollection so that I can use it in datagrids etc.  Now up until this part is all good.  My problem is when getting a single instance from the results list, updating it by moving data around in a new datagrid for example - I want to interact with the webservice again to do an create/update.  This is where I am having problems - because these webservice methods require the complex object as a parameter - I am struggling to understand how I can convert the array collection instance back to my complex object without iterating over it and casting it back (maybe this is the only way - but I am hoping not).
    I am hoping that there is a simple solution that I am missing and that there is some smart cookie out there that could provide me with an answer - or at least somewhere to start looking. I guess if I have no other alternative - maybe I need to get the people who built the service to change it to accept an array - and let them do the conversion.
    Any help would be greatly appreciated.
    Bert

    Hi Bert,
    According to my knowledge you can use describeType(Object) method which will return an XML... That XML will contain Properties and values just iterate through the XML and create a new Object..   Probably u can use this method...
    public function getObject(reqObj:Object,obj:Object,instanceName:String,name:String=null,index:int=-1):Obj ect
                if(!reqObj)
                    reqObj = new Object();
                var classInfo:XML = describeType(obj);
                var className:String = instanceName;
                if(name!=null)
                    className=name+"."+className;
                if(index!=-1)
                    className=className+"["+index+"]";
                for each (var v:XML in classInfo..accessor)
                    var attributeName:String=v.@name;
                    var value:* = obj[attributeName]
                    var type:String = v.@type;
                    if(!value)
                        reqObj[className+"."+attributeName] = value; 
                    else if(type == "mx.collections::ArrayCollection")
                        for(var i:int=0;i<value.length;i++)
                            var temp:Object=value.getItemAt(i);
                            getReqObject(reqObj,temp,attributeName,className,i);
                    else if(type == "String" || type == "Number" || type == "int" || type == "Boolean")
                        reqObj[ className+"."+attributeName] = value; 
                    else if (type == "Object")
                        for (var p:String in value)
                            reqObj[ className+"."+attributeName+"."+p] = value[p];
                    else
                        getReqObject(reqObj,value,attributeName,className);
                return reqObj;
    Thanks,
    Pradeep

Maybe you are looking for

  • Interaction Record ticket to Email

    Hi Experts I am stuck with this problem: I create a service ticket from ICweb, so first an interaction Record is created then service ticket created. Let's say the service ticket is passed to somebody else to have a look, so with the inbox i look at

  • Copy/Capture Adjustment Layer settings using Javascript

    Hi, For last couple of days I'm trying to copy adjustment layer settings via Javascript after adjustment layer has been already created. General idea is to capture adjustment layer settings and save them to JSON file for future preset etc. I was hopi

  • Why do I keep getting a Network time out message when trying to get current update on my 3GS?

    Why do I keep getting, "Network timed out error", when trying to get latest update to my IPhone 3GS? Have never had trouble before.

  • Why my computer can not install itunes?

    Why can not my computer install itunes? I am a Chinese user. My computer is Windows7 I installed itunes, but once I uninstalled the update failed now can not reinstall. First compilation of the installation error, please refer to help and support to

  • Application.getRealPath("/") problem

    Hi all I'm learning JSP now with a big book, and I'm having the following problem. My script xxx.jsp is saved to D:\Programme\Eclipse3\workspace\jsp-kompendium\csv\get_data.jsp and its path is /jsp-kompendium/csv/get_data.jsp Now application.getRealP