Help with array / indexed property

Hi,
I am trying to save the value of multiple dropdowns in the Session Bean. Therefore, I created an index property "rule" in the Bean.
Each time the page is loadad, a different dropdown appears depending on the previous choices. If the ok button is clicked, the action is performed to save the current dropdown value in the index property:
public String button1_action() {
int cnt = 1;
// if page was loaded before, replace count
if (getAdminBean().getCount() > 0) {
cnt = getAdminBean().getCount() +1;
} else {
// save current count in Session
getAdminBean().setCount(cnt);
setValue("#{AdminBean.rule[cnt-1]}", selectme.getValue());
This is the error message:
Exception Details: javax.faces.el.PropertyNotFoundException
Error setting property '-1' in bean of type null
Possible Source of Error:
Class Name: com.sun.faces.el.PropertyResolverImpl
File Name: PropertyResolverImpl.java
Method Name: setValue
Line Number: 153
I have played around and even the following code would not work to save a value at the first position of the index property:
setValue("#{AdminBean.rule[0]}", selectme.getValue());
Can anyone help?
Thanks,
Nils

You can not set the index as you use here i.e
#{AdminBean.rule[cnt-1]}
is not correct. Because in JSF the "[" is used for some other purpose.
I would suggest you to use another property called "index"
setValue("#{AdminBean.index", cnt-1);
setValue("#{AdminBean.rule", selectme.getValue());
Inside the session bean, in the method setRule get the index (already set) and place your value in the correct indexed array.
Same logic you can use to get the value too
setValue("#{AdminBean.index", cnt-1);
getValue("#{AdminBean.rule");
the method getRule() should get the value for the index and return it.
- WInston
http://blogs.sun.com/roller/page/winston?catname=Creator

Similar Messages

  • Help with array question

    hi,
    i need some help with this piece of code. wat would it output to the screen?
    int [] theArray = { 1,2,3,4,5};
    for (int i = 1; i < 5; i++)
    System.out.print(theArray * i + "; ");
    would it output 1 * 1;
    2 * 2;...
    thanx
    devin

    Ok...
    1] Your index into the array is off by 1 - remember that array indexing starts from 0.
    2] You cannot multiply an array object. The contents? fine , go ahead but NOT the array
    so your output should be something like:
    operator * cannot be applied to int[] :d
    try
    int[] theArray = {0,1,2,3,4,5};
    for(int i = 1;i<6;i++)
         System.out.print(theArray*i+";");
    giving you an output of 1;4;9;16;n...
    if you were looking for the output stated change
    System.out.print(theArray*i+";");
    to
    System.out.print(theArray[i]+"*"+i+";");done...

  • Help with array's again

    Hello again
    I know im probably getting on peoples nerves now, but im still working on my lottery simulation. Ive tried different techniques, all of which have worked so far but now im trying a different way and have encountered a problem i cannot de-bug.
    Please can you have a look at my code, its probably obvious to most of you experts.
    int[] winners = new int[5];
    winners[0] = Lotto.drawBall();
    int num = Lotto.drawBall();
    for(int counter = 1; counter<5;){
        while(counter <= winners.length){
            if(num==winners[0] || num==winners[1] || num==winners[2] || num==winners[3] || num==winners[4]){
                num = Lotto.drawBall();
            else{
                winners[counter] = num;  //here is where my exception occurs
                counter++;
    System.out.print(winners[0]);
    System.out.println();
    System.out.print(winners[1]);
    System.out.println();
    System.out.print(winners[2]);
    System.out.println();
    System.out.print(winners[3]);
    System.out.println();
    System.out.print(winners[4]);I get an Array index out of bounds exception but i cannot see how.
    Please can you help me again??
    D_H

    int[] winners = new int[5];
    winners[0] = Lotto.drawBall();
    int num = Lotto.drawBall();
    for(int counter = 1; counter<5;){
    while(counter <= winners.length){ /*Here you should use counter < winners.length*/
    if(num==winners[0] || num==winners[1] ||
    s[1] || num==winners[2] || num==winners[3] ||
    num==winners[4]){
    num = Lotto.drawBall();
    else{
    winners[counter] = num;  //here is where
    re is where my exception occurs
    counter++;
    System.out.print(winners[0]);
    System.out.println();
    System.out.print(winners[1]);
    System.out.println();
    System.out.print(winners[2]);
    System.out.println();
    System.out.print(winners[3]);
    System.out.println();
    System.out.print(winners[4]);I get an Array index out of bounds exception but i
    cannot see how.
    Please can you help me again??
    D_Hcheck the while condition you are using count until it is equal to 5

  • Need help with Arrays

    Hey guys, I'm a beginner programmer and I'm having a bit of a tough time with arrays. I could really use some help!
    What I'm trying to do is roll one die and then record the rolls.
    Here is my sample I/O:
    How many times should I roll a die?
    -> 8
    rolling 8 times
    2, 1, 5, 6, 2, 3, 6, 5
    number of 1's: 1
    number of 2's: 2
    and so on....
    Here is my incomplete code at this moment:
    //CountDieFaces.java
    import java.util.Scanner;
    import java.io.*;
    import library.Gamble;
    public class CountDieFaces
        //prompt for and read in: number of times user wants to roll one die
        //simulate rolling a die that many times, counting how many times each face 1 thru 6 comes up
        //print out: each roll
        //AND the total number of times each face occured and the percentage of the time each face occured.
        Scanner scan = new Scanner(System.in);
        int[] faceCount= {0,0,0,0,0,0,0};
        int dice;
        System.out.println("How many times would you like to roll the die?");
        int dieCount = scan.nextInt();
        int dieRoll = Gamble.rollDie(); // Main calling class method
        int count = 1;
        while(count < dieCount)
            System.out.println(faceCount[count]);
            count++;
    }Here is the gamble library:
    //Gamble.java
    package library;
    public class Gamble
         // returns 1, 2, 3, 4, 5, or 6
         public static int rollDie()
              int dieRoll = (int)(Math.random()*6)+1;
              return dieRoll;
    }and here are the errors I have so far:
    ----jGRASP exec: javac -g CountDieFaces.java
    CountDieFaces.java:19: <identifier> expected
         System.out.println("How many times would you like to roll the die?");
         ^
    CountDieFaces.java:19: illegal start of type
         System.out.println("How many times would you like to roll the die?");
         ^
    CountDieFaces.java:25: illegal start of type
         while(count < dieCount)
         ^
    CountDieFaces.java:25: > expected
         while(count < dieCount)
         ^
    CountDieFaces.java:25: ')' expected
         while(count < dieCount)
         ^
    CountDieFaces.java:26: ';' expected
         ^
    CountDieFaces.java:27: illegal start of type
              System.out.println(faceCount[count]);
              ^
    CountDieFaces.java:27: ';' expected
              System.out.println(faceCount[count]);
              ^
    CountDieFaces.java:27: invalid method declaration; return type required
              System.out.println(faceCount[count]);
              ^
    CountDieFaces.java:27: ']' expected
              System.out.println(faceCount[count]);
              ^
    CountDieFaces.java:27: ')' expected
              System.out.println(faceCount[count]);
    I'm really confused with how a the gamble library gets put into the array, so any help is appreciated! Also if anyone could explain the errors to me, I would really appreciate it.
    thanks in advance,
    wootens
    Edited by: Wootens on Oct 18, 2010 8:55 PM

    D'oh!
    Thanks you guys, fixed that. Although I'm having trouble with storing the die roll in the array. Any suggestions?
    java.io.*;
    public class CountDieFaces
        //prompt for and read in: number of times user wants to roll one die
        //simulate rolling a die that many times, counting how many times each face 1 thru 6 comes up
        //print out: each roll
        //AND the total number of times each face occured and the percentage of the time each face occured.
        public static void main(String[] args)
            Scanner scan = new Scanner(System.in);
            int[] faceCount= {0,0,0,0,0,0};
            int dice;
            System.out.println("How many times would you like to roll the die?");
            int dieCount = scan.nextInt();
            int dieRoll = rollDie(); // Main calling class method
            int count = 0;
            while(count < dieCount)
                System.out.println(faceCount[dieRoll]);
                count++;
        public static int rollDie()
            int dieRoll = (int)(Math.random()*6)+1;
            return dieRoll;
    }Wootens

  • Help with context index with /, -, @

    Hi all!
    I have just start work with oracle. I have a problem with context index. Please help me. My problem is :
    I have two column 'name' and 'address'. I index two column with context index (for example : Two index have name is 'Index1' and 'Index 2' ). I set parameter ('STOPLIST ctxsys.empty_stoplist') and i insert four rows such as : ('A','80/3 cong hoa'), ('B','80-3 cong hoa'), ('C','80@3 cong hoa'), ('D','80 3 cong hoa'). But when i execute this select :
    select * from tablename where contains(address, '3 cong hoa') > 0
    Result will return to me 4 rows But i just want one rows is ('D', '80 3 cong hoa').
    I know oracle will convert character '/', '-', '@' to space so result will return 4 rows and i don't know how to oracle keep character '/', '-', '@' when oracle index. I just want to add with 'Index2' for column 'address' and i don't want to add with 'Index1' for column 'name'
    Please help me, and thanks for your attention

    So you want "/", "-" and "@" to link tokens, but you want "." to break numeric tokens?
    OK, we can do that - though it seems a slightly odd requirement.
    There are two special characters NUMJOIN and NUMGROUP which are used for purely numeric tokens. The default will vary by locale, but for English-speaking locales the defaults are "." and "," - so a number such as 1,234,567.89 will be treated as a single token. In French (and other) speaking locales, they are reversed since numbers are normally written as 1.234.567,89.
    If you want to disable these NUMJOIN and NUMGROUP characters, so that numbers are always split into component tokens, then you can set both of the to the space character (it won't allow NULL or '', which would be more logical in my opinion).
    drop table foo;
    create table foo (bar varchar2(200));
    insert into foo values ('80/3 cong hoa');
    insert into foo values ('80-3 cong hoa');
    insert into foo values ('80@3 cong hoa');
    insert into foo values ('80 3 cong hoa');
    insert into foo values ('80.3 cong hoa');
    exec ctx_ddl.drop_preference('foo_lexer')
    exec ctx_ddl.create_preference('foo_lexer', 'basic_lexer')
    exec ctx_ddl.set_attribute('foo_lexer', 'PRINTJOINS', '/-@')
    exec ctx_ddl.set_attribute('foo_lexer', 'PRINTJOINS', '/-@')
    exec ctx_ddl.set_attribute('foo_lexer', 'NUMJOIN', ' ')
    exec ctx_ddl.set_attribute('foo_lexer', 'NUMGROUP', ' ')
    create index foo_index on foo(bar) indextype is ctxsys.context
    parameters ('lexer foo_lexer');
    select * from foo where contains (bar, '3 cong hoa') > 0;Output is:
    BAR
    80 3 cong hoa
    80.3 cong hoa

  • Need Help with Array.sort and compare

    Hi
    I have a big problem, i try to make a java class, where i can open a file and add new words, and to sort them in a right order
    Ok everthing works fine, but i get a problem with lower and upper cases.
    So i need a comparator, i tried everything but i just dont understand it.
    How do i use this with Array.sort??
    I hope someone can help me

    Okay, you want to ignore case when sorting.
    There are two possibilities: Truly ignore case, so that any of the following are possible, and which one you'll actually get is undefined, and may vary depending on, say, which order the words are entered in the first place:
    English english German german
    english English german German
    English english german German
    english English German german
    The second possibility is that you do consider case, but it's of lower priority--it's only considered if the letters are the same. This allows only the first two orderings above.
    Either way, you need to write a comparator, and call an Arrays.sort method that takes both array and Comparator.
    The first situation is simpler. Just get an all upper or lower case copy of the strings, and then compare thosepublic int compare(Object o1, Object o2) {
        String s1 = ((String)o1).toUpper();
        String s2 = ((String)o1).toUpper();
        return s1.compareTo(s2);
    } You'll need to add your own null check if you need one.
    For the second way, your comparator will need to iterate over each pair of characters. If the characters are equal, ignoring case, then you compare them based on case. You pick whether upper is greater or less than lower.
    Of course, the need to do this assumes that such a method doesn't alrady exist. I don't know of one, but I haven't looked.

  • Please Help With Arrays

    I really need some help with the following two methods:
    - A method fillArray() that accepts an integer array as a parameter and fills the array with random integers. I am encouraged to use Math.random()
    - A method printArray() that accepts an integer array as a parameter and outputs every element of the array to the standard output device. I am encouraged to use print instead of println in order to save paper.
    Thanks so much for your help.

    public class Test {
       public static void main (String[] args){
           int[] intArray = new int[20];
           fillArray(intArray);
           printArray(intArray);
       public static void fillArray (int[] intArray){
           for (int i = 0; i < intArray.length; i++) {
               intArray[i] = (int) (Math.random()*1000);
       public static void printArray (int[] intArray){
           for (int i = 0; i < intArray.length; i++) {
               int i1 = intArray;
    System.out.print(i1+",");
    System.out.println("");

  • Help with array program!!

    hi friends
    i am a new comer to java and I have been studying Arrays recently. I came across this program on the internet ( thanks to Peter Williams)
    package DataStructures;
    import java.util.NoSuchElementException;
    * An array implementation of a stack
    * @author Peter Williams
    public class StackArray implements Stack {
    private int top; // for storing next item
    public StackArray() {
    stack = new Object[1];
    top = 0;
    public boolean isEmpty() {
    return top == 0;
    public void push(Object item) {
    if (top == stack.length) {
    // expand the stack
    Object[] newStack = new Object[2*stack.length];
    System.arraycopy(stack, 0, newStack, 0, stack.length);
    stack = newStack;
    stack[top++] = item;
    public Object pop() {
    if (top == 0) {
    throw new NoSuchElementException();
    } else {
    return stack[--top];
    interface Stack {
    * Indicates the status of the stack.
    * @return <code>true</code> if the stack is empty.
    public boolean isEmpty();
    * Pushes an item onto the stack.
    * @param <code>item</code> the Object to be pushed.
    public void push(Object item);
    * Pops an item off the stack.
    * @return the item most recently pushed onto the stack
    * @exception NoSuchElementException if the stack is empty.
    public Object pop();
    class StackDemo {
    public static void main(String[] args) {
         Stack s = new StackArray();
         // Stack s = new StackList();
         for (int i = 0; i < 8; i++) {
         s.push(new Integer(i));
         while (!s.isEmpty ()) {
         System.out.println(s.pop());
    what baffles me is as below:
    there is an 'if' construct in the push method, which talks about if(top == stack.length)
    I fail to understand how top can at any time be equal to stack.length.
    Could you help me understand this program?
    a thousand apologies and thanks in advance

    figurativelly speaking:
    if you take an array and put it standing on your tesk, so that start of array points to floor, and end of array points to roof, then you can start filling that array as stack.
    if you put books into stack, then you push (put) them on top of the stack, so the first book ever but into stack is adiacent to array element with index zero (0) and then second book in stack would be adiacent to array element that has index one (1) and so on.
    if you have array of size 5, then fift book in stack would be adiacent to array element with index four (4)
    after pushing that Object to stack, the top variable will get incremented (top++ in code) and be equal to size of array.
    however, if you would like to push another Object to stack, then it would fall over the end of the array, so longer array is needed...

  • Help with set(index, object) please / new to java

    private static void setDobject(Rectangle [] setrect)
              LinkedList<Rectangle> rects = new LinkedList<Rectangle>();
              Rectangle myrectangle = new Rectangle(9.0,9.0);                                                                  
                 rects.set(1,myrectangle);
              for(Rectangle x : setrect)
                   System.out.print("Rectangle: ");
                   System.out.println(x.getLength() + " by " + x.getWidth());
              }  //End of for loop
         }  //End of unsorted
         }  the other previous code works, i have used the add(object) and it works here is the code for that:
    private static void addDobject(Rectangle [] addrect)
              LinkedList<Rectangle> rects = new LinkedList<Rectangle>();
              Rectangle myrectangle = new Rectangle(9.0,9.0);                                                                  
                 rects.add(myrectangle);
                 for(Rectangle x : rects)
                   System.out.print("Rectangle: ");
                   System.out.println(x.getLength() + " by " + x.getWidth());
              }  //End of for loop
              System.out.println();
         }  //End of unsorted
    this is the output error it is giving me :
    Part 1 : An Array List of Rectangles
    Enter length or 999 to exit: 3
    Enter width: 2
    Enter length or 999 to exit: 1
    Enter width: 2
    Enter length or 999 to exit: 10
    Enter width: 20
    Enter length or 999 to exit: 999
    Rectangle: 3.0 by 2.0
    Rectangle: 1.0 by 2.0
    Rectangle: 10.0 by 20.0
    Display Object with added item
    Rectangle: 3.0 by 2.0
    Rectangle: 1.0 by 2.0
    Rectangle: 10.0 by 20.0
    Rectangle: 9.0 by 9.0
    Displaying Objects with SET item
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size:
    0
    at java.util.LinkedList.entry(LinkedList.java:365)
    at java.util.LinkedList.set(LinkedList.java:328)
    at Lab11.setDobject(Lab11.java:129)
    at Lab11.main(Lab11.java:78)
    Press any key to continue...
    finally here is the Rectangle class i'm using:
    public class Rectangle
        private double length;     // Instance variables
        private double width;
        public Rectangle(double l, double w)  // Constructor method
            length = l;
            width = w;
        } // end Rectangle constructor
        public double getLength()             // getter 
             return length;
        } // end getLength
         public double getWidth()             // getter 
             return width;
        } // end getWidth
        public void setLength(double l)      // setter 
             length = l;
        } // end setLength
         public void setWidth(double w)     // setter 
             width = w;
        } // end setWidth
         public double calculateArea()         // calculation method
            return length * width;
        } // end calculateArea
        public void displayRectangle()         // display method
            System.out.println("Rectangle Length = " + length);
            System.out.println("Rectangle Width = " + width);               
        } // end displayRectangle
    } // Rectangle ClassHope you can help guys! thanks!

    LinkedList<Rectangle> rects = new LinkedList<Rectangle>();rects is an empty LinkedList at this point. It has no elements added to it.
    rects.set(1,myrectangle);So you can't set the item at index 1 (the 2nd element in the list) because it doesn't even exist. You need to add items to it.

  • Need Help with Arrays/Text

    I'm trying to create a flash program that uses it's own code to send and create images. Each square has a colour and that colour gets added into the array. A black, then grey, then white is:
    filecode = ["Bl", "Gr", "Wh"];
    That works fine, but when I try to paste it into an Input text box it will only fill in the first part of the array.
    filecode = ["Bl,Gr,Wh"];
    So the program has NO idea what I want.
    The only ways I can think of fixing this is by putting in 402 text boxes to suit every box...But every one of them needs a Variable Name.
    Or by sending the information straight into the array. But this way you are just looking at what you just drew, and that is not at ALL practical.
    Helping me with this headache will be greatly apprectiated.
    FlashDrive100.

    If you can explain the first part of your posting it might become a little clearer what you are trying to do and what isn't working... particularly this...
    " when I try to paste it into an Input text box it will only fill in the first part of the array."
    I can't speak for anyone else, but at this point, I share your file's problem... not knowing what you want.

  • Help with arrays and Exception in thread "main" java.lang.NullPointerExcept

    Hi, I have been having trouble all day getting this array sorted and put into a new array. I think it is something simple with my nested loops in sortCityArray() that is causing the problem. Any help would be greatly appreciated. The error is thrown on line 99 at Highway.sortCityArray(Highway.java:99)
    import java.util.Scanner;
    import java.io.*;
    import java.util.Arrays;
    public class Highway
    private String[] listOfCities=new String[200];
    private City[] cityArray=new City[200];
    private City[] sortedCityArray=new City[200];
    private String city="";
    private String city2="";
    private String fileName;
    private City x;
    private int milesToNextCity;
    private int milesAroundNextCity;
    private int speedToNextCity;
    public Highway(String filename)
    String fileName=filename;//"I-40cities.txt";
           File myFile = new File(fileName);
           try {
           Scanner scan=new Scanner(myFile);
           for(int i=0; scan.hasNextLine(); i++){
           String city=scan.nextLine();
           String city2=scan.nextLine();
           int milesToNextCity=scan.nextInt();
           int milesAroundNextCity=scan.nextInt();
           int speedToNextCity=scan.nextInt();
                   if(scan.hasNextLine()){
              scan.nextLine();
           cityArray=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
    // System.out.println(cityArray[i].getCity());
    // System.out.println(cityArray[i].getNextCity());
    // System.out.println(cityArray[i].getLengthAB());
    // System.out.println(cityArray[i].getLengthAroundB());
    // System.out.println(cityArray[i].getSpeedAB());
    catch (Exception e) {
    System.out.println(e);
    //return cityArray;
    /*public City[] doCityArray(){
    File myFile = new File(fileName);
    try {
    Scanner scan=new Scanner(myFile);
    for(int i=0; scan.hasNextLine(); i++){
    String city=scan.nextLine();
    String city2=scan.nextLine();
    int milesToNextCity=scan.nextInt();
    int milesAroundNextCity=scan.nextInt();
    int speedToNextCity=scan.nextInt();
         if(scan.hasNextLine()){
              scan.nextLine();
    cityArray[i]=new City(city,city2,milesToNextCity,milesAroundNextCity,speedToNextCity);
    // System.out.println(cityArray[i].getCity());
    // System.out.println(cityArray[i].getNextCity());
    // System.out.println(cityArray[i].getLengthAB());
    // System.out.println(cityArray[i].getLengthAroundB());
    // System.out.println(cityArray[i].getSpeedAB());
    catch (Exception e) {
    System.out.println(e);
    return cityArray;
    public City[] sortCityArray(){
    sortedCityArray[0]=new City(cityArray[0].getCity(),cityArray[0].getNextCity(),cityArray[0].getLengthAB(),cityArray[0].getLengthAroundB(),cityArray[0].getSpeedAB());
    for(int j=0; j<cityArray.length; j++ )
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
              break;
    /*     for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[j].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[j+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
    //     j++;
    System.out.println(sortedCityArray[0].getCity());
    System.out.println(sortedCityArray[0].getNextCity());
    System.out.println(sortedCityArray[0].getLengthAB());
    System.out.println(sortedCityArray[0].getLengthAroundB());
    System.out.println(sortedCityArray[0].getSpeedAB());
    System.out.println(sortedCityArray[1].getCity());
    System.out.println(sortedCityArray[1].getNextCity());
    System.out.println(sortedCityArray[1].getLengthAB());
    System.out.println(sortedCityArray[1].getLengthAroundB());
    System.out.println(sortedCityArray[1].getSpeedAB());
    System.out.println(sortedCityArray[2].getCity());
    System.out.println(sortedCityArray[2].getNextCity());
    System.out.println(sortedCityArray[2].getLengthAB());
    System.out.println(sortedCityArray[2].getLengthAroundB());
    System.out.println(sortedCityArray[2].getSpeedAB());
    System.out.println(sortedCityArray[3].getCity());
    System.out.println(sortedCityArray[3].getNextCity());
    System.out.println(sortedCityArray[3].getLengthAB());
    System.out.println(sortedCityArray[3].getLengthAroundB());
    System.out.println(sortedCityArray[3].getSpeedAB());
    System.out.println(sortedCityArray[4].getCity());
    System.out.println(sortedCityArray[4].getNextCity());
    System.out.println(sortedCityArray[4].getLengthAB());
    System.out.println(sortedCityArray[4].getLengthAroundB());
    System.out.println(sortedCityArray[4].getSpeedAB());
    return cityArray;
    /*public String[] listOfCities(){
    File myFile = new File("I-40cities.txt");
    try {
    Scanner scan=new Scanner(myFile);
    for(int i=0; scan.hasNextLine(); i++){
         String city=scan.nextLine();
         city=city.trim();
    scan.nextLine();
    scan.nextLine();
         listOfCities[i]=city;
         System.out.println(listOfCities[i]);
    catch (Exception e) {
    System.out.println(e);
    return listOfCities;
    public static void main(String args[]) {
    Highway h = new Highway("out-of-order.txt");
    h.sortCityArray();

    the ouput is perfect according to the print lines if I use (increase the int where j is in the loop manually by one) :
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[0].getNextCity().equals(cityArray.getCity())){
              sortedCityArray[0+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
              break;
         for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[1].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[1+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[2].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[2+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
              for(int i=0; i<cityArray.length ;i++)
              if(sortedCityArray[3].getNextCity().equals(cityArray[i].getCity())){
              sortedCityArray[3+1]=new City(cityArray[i].getCity(),cityArray[i].getNextCity(),cityArray[i].getLengthAB(),cityArray[i].getLengthAroundB(),cityArray[i].getSpeedAB());
         break;
    But I cant do this for 200 elements. Are the loops nested right?
    Edited by: modplan on Sep 22, 2008 6:49 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need Small Help with Arrays.

    I have this question i wanna ask...Could anyone help me with this code.
    Assume that the array arr has been declared. how do i write a statement that assigns the next to last � element of the array to the variable x , which has already been declared.

    Of course, if you don't know the size until run time, you'll want to check that the array size is greater than 1, else there won't BE a next to last element.

  • Need some help with Adobe Indexes

    Hello Reader forum! I'm looking for help to make our lives in IT easier.
    We have about 15 pdf files with pdx or index files setup for quick searching. They reside in seperate folders off of a network share.
    Problem is we are about to migrate the share to a new server and about 50 to 60 users have there local installation setup pointing to those shares via \\UNCname. So once we move the share we will have problems, being that we would have to walk to each PC and manually update the index file locations for each user.
    So my question/desire is to either copy the specific file that houses the index paths to all of the PC's or perhaps use VB Script to change all of the references automatically.
    They should all be on 9.0 reader at least.
    Any ideas, suggestions, point me in the right direction would be appreciated.

    Ping this up to the top and looking for any help!

  • Help with arrays...Please Help

    Hello,
    Iam trying to make a library system. I have three classes, one for the GUI, User class, and Users class. User class instantiates an object with all the relevant data like, Name, Age, Address, etc. The Users class contains a array of User Objects.
    With this program I have to be able to create users, display users and delete users. The problem Iam having is displaying them. (I think I correctly store the User Objectsin the array, and Iam having problems retreiving them). The thing is when I run the program I don't get any exception errors, just nothing gets displayed!
    Here is part of my code:
    public class Users {
    //declaring variables
    public Users (){
    initialiseArray();
    public void initialiseArray(){
    userArray = new User [50];
    // This method first checks to see if there is enough room for a new
    // user object. If there is the object is added to the array, if there is'nt
    // Then method expandUserArray is called to make room for the user
    public void addUser( User user)
    if (userArraySize == userArray.length) {
    expandUserArray();
    userArray[userArraySize] = user;
    userArraySize++;
    // In this method first the user is searched for in the array, if found
    // Then method decreaseUserArray is called to delete the user
    public void deleteUser ( User user )
    location = 0;
    while (location < userArraySize && userArray[location] != user) {
    location++;
    if (userArray[location] == user) {
    decreaseUserArray(location);
    public void displayUsers( ){
    for (int i = 0; i < userArraySize; i++) {
    usersInformation += "\n" + (userArray.getUserName());
    usersInformation += "\t" + (userArray[i].getUserID());
    usersInformation += "\t" + (userArray[i].getUserAddress());
    public String getUserInformation(){
    //usersInformation = userInformation.toString();
    return usersInformation;
    // The User is deleted by shifting all the above users one place down
    private void decreaseUserArray(int loc)
    userArray[loc] = userArray[userArraySize - 1];
    userArray[userArraySize - 1] = null;
    userArraySize--;
    // This method increase the size of the array by 50%
    private void expandUserArray( )
    int newSize = (int) (userArray.length * increasePercentage);
    User newUserArray[] = new User[newSize];
    for (int i = 0; i < userArray.length; i++) {
    newUserArray[i] = userArray[i];
    userArray = newUserArray;
    Is there anything wrong with my arrays??? Here is part of my code for action performed:
    void addUserButton_actionPerformed(ActionEvent e) {
    newUserName = userNameTextField.getText();
    newUserAddress = userAdressTextField.getText();
    newUserID = Integer.parseInt ( userIDTextField.getText());
    User newUser = new User (newUserName, newUserAddress, newUserID);
    Users users = new Users();
    users.addUser(newUser);
    clearButton();
    void displayUsersButton_actionPerformed(ActionEvent e) {
    Users users = new Users();
    users.displayUsers();
    displayUsersTextArea.append (users.getUserInformation());
    void deleteUserButton_actionPerformed(ActionEvent e) {
    //Still incomplete
    Thanks for your help!

    First, PLEASE USE THE SPECIAL TOKENS FOUND AT
    http://forum.java.sun.com/faq.jsp#messageformat WHEN
    POSTING CODE!!!! Sorry about that, Iam new and I did'nt know about Special Tokens.
    As far as the problem, let me start out by asking if
    you've considered using a class that implements the
    List interface. Perhaps Vector or ArrayList would
    make a better choice since they already handle
    "growing" and "shrinking" for you.I tried using vector arrays but it got too complicated. It was very easy to add and remove objects from the vector but I never figured out how to display all the objects with all the data.
    public void displayUsers( ){
    for (int i = 0; i < userArraySize; i++) {
    usersInformation += "\n" +
    " + (userArray.getUserName());   //what is
    usersInformation?  Also, how does getUserName(),
    getUserID(), getUserAddress() know which user object
    to operate on if these are methods of userArray?
    usersInformation += "\t" +
    " + (userArray.getUserID());     //I'm guess you've
    only posted "some" of your code. 
    usersInformation += "\t" +
    " + (userArray.getUserAddress());//Try posting all
    that you have so far, and please use the special
    tokens to format your code.
    }I made a mistake while I was cutting & pasting my code. It should be for example:
    usersInformation += "\n" (userArray.getUserName());
    The comment about instanciating a new Users for each
    actionPerformed is on point. You are replacing your
    Usres with a new object each time.Yep this was the problem. I just changed the constructor, declared and
    created object of Users elsewhere.
    Thanks for your help!

  • Help with Array of Arrays

    import java.util.Arrays;
    import java.util.Date;
    import java.util.List;
    public class StockDay
        private String[] stockDayData;
        List stockDays = new ArrayList();
        public StockDay(String stockData)
            stockDayData = new String[6];
            String[] stockDayData= stockData.split(",");
            stockDays.add(stockDayData[]);
    }I have an outside class calling this class with a string of data separated by commas. I am trying to separate the data so that each time the method is called, each piece of the data (6 total) is put into an array list. Then that array list is put into an array list of arrays. I am sorry if I have not made this clear, I will try again. I want an array of arrays, and the interior arrays will contain 6 pieces of information each from the string that is given to the method, and each separated by commas.
    Any help is much appreciated. I am also curious how I can accesses one piece of the data at a time, this is what I am thinking for this:
    data = arraylist1[#].arraylist2[#]this would set data equal to whatever is in arraylist2[#]
    Thank you very much.

    ActingRude wrote:
    I meant just a simple Array I guess.Note the difference between Array and array. Class names start with uppercase in java. There is a class called Array, but it's just a utility class, and isn't part of arrays.
    .. like I am using above? I was under the impression that the biggest syntax difference between an array(fixed number of items) and an ArrayList(unfixed number of items) was the use of the [] and () That's one of many syntactical differences, yes, but the main difference is not in the syntax. arrays are part of the Java language, have special handling because of that, and are faster and smaller than ArrayLists. ArrayList is part of the API, and didn't exist until Java 1.2 (about 5-6 years into Java's life, I think), and is built on top of an array.
    UnsupportedOperationException:
    null (in java.util.AbstractList)I have no idea what is causing this, I can only assume that I am doing something wrong...It looks like you're tyring to add null to an ArrayList and it doesn't like it. I thought ArrayList accepted null elements, but I could be wrong. Paste in the exact line that's causing it, and any declarations necessary to clarify any variables used on that line.

Maybe you are looking for

  • How to add chapters to exported Apple TV movies

    (The process works with QuickTime 7.4 and Final Cut Express 4.0) To add chapters to movies exported from FCE using the "Apple TV" preset in the Export menu: In a text editor, like TextEdit in the Applications folder, type your list of chapters. Make

  • Function to Generate a Sequential incremental Number by Group of Records

    I have a table with several columns and I need to compute a sequential number by group of records FIELD1 FIELD2 FIELD3 FIELD4 FIELD5 AAAAAA A1 JOHN 01/01/61 NULL AAAAAA A3 PAUL 01/01/71 NULL AAAAAA A3 MARY 01/01/02 NULL AAAAAA A4 CARL 01/01/04 NULL B

  • Unable to Find supply demand Item

    Hi All, While attempting to open a item from Inventory >On Hand> Item Supply Demand > I am getting the following error. Please assist me. Date falls outside the boundaries of the workday calendar Cause: The current date is outside the range of valid

  • PDF Link doesn't open

    I have several PDF's linked on my website and they all open, just recently when I tried to link another one it won't open. You can see the website has the correct link (because it shows it on the bottom left hand side of the screen) but it will just

  • Implement Drag and drop functionality in my application

    I want to drag image from one UIImageView to other UIImageView. Is there any event handle to this drag and drop functionality. Any one have different idea to handle this. than please reply. Any coding idea related to this?