Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lol help

Name: Anonymous 2008-03-15 20:39

Noob programmer here, I can't figure out why I keep getting the error "Cannot find symbol class ArrayList".


import java.awt.*;
import javax.swing.*;
import java.util.Scanner;

public class MyArray{  
  


     public static void main()     {
        int i=0, thesame, size;         
      
        ArrayList<String> list = new ArrayList<String>();
         Scanner input = new Scanner(System.in);
         bString = "done";
         for(i=0;i!=2.5;i++){
              System.out.print("Enter a name");
              nextWord = input.nextString;
              list.add(i, nextWord);
              boolean theSame = bString.equals("Done");
              if(theSame = 0)
                  i = 1.5;
         }   
          int size = list.size();
          for(i=0;i<=0;i++){
              String temp = copy.get(i);
              System.out.print(temp);
            }  
               
               
    }
    public ArrayList sort(ArrayList list){
      
        int top, i, maxIdx, copy1;
       
       
        ArrayList<Sring> copy = new ArrayList<String>(list.size());
       
    for (int i = 0;i < list.size;i++)
        copy.add((string)list.get(i));
    for (int top=copy.size-1;top > 0;top--) {
        ArrayList maximum = ((string)copy.get(0));
        int maxIdx = 0;

        for (int search=1;search <= top;search++){
            String name = ((string)copy.get(search)) ;
            String topName = ((string)copy.get(top)) ;
          
            if (name.compareTo(top) = 1) {
                 Sting maximum = ((string)copy.get(search));
                 maxIdx = search;
            }
        }
        if (maxIdx != top) {
        ArrayList swap = ((string)copy.get(top));
        copy1= ((string)copy.get(maxIdx));
        copy.set(top,copy1);
        copy.set(maxIdx,swap);
       }
     }
    return copy;


}
}

Name: Anonymous 2008-03-16 19:33

>>29
You declare thesame as an int, but never use it. Remove it. It's only there to confuse it with the boolean theSame.
You declare int size, assign the size of the array to it, and then never use it, instead using copy.size().

In if (theSame = true), you're using an assignment instead of a comparison. Assignment returns the value being assigned, so the net result is that -1 is always assigned to i.
Not that it matters, since the for loop it's in will never execute, since i starts out as 0, which is not less than 0.

But seriously, don't add to ArrayLists using indices directly unless you have to. The entire point of ArrayList is that it deals with that stuff itself.
And when retrieving yours Strings from it, you don't have to cast to String, since you're already using generics. You don't even need that temp variable. Just pass it directly to System.out.print().

And that's just some of what's wrong with your main method. I'm not even going to look at the other one.

If you aren't a troll, get the fuck away from computers right now. You're never going to be an even halfway competent code monkey, let alone a real programmer.
If you do intend to stay in this field, at the very least learn to format your fucking code, so other people can clean up after you.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List