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

Pages: 1-4041-

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-15 20:41

btw, its a program for sorting names alphabettically(selecion sort)

Name: Anonymous 2008-03-15 20:41

import java.util.ArrayList;

Name: Anonymous 2008-03-15 20:42

>>3
wtf really? god damn i cant believe i forgot about that, thanks

Name: Anonymous 2008-03-15 20:43

for(i=0;i!=2.5;i++)
for(i=0;i<=0;i++)

wat

Name: Anonymous 2008-03-15 20:52

int i=0, thesame, size;
Java standard: One declaration per line

Also, declare variables in the lowest possible scope, since you're only using i in for loops just use:
for (int i = 0; i < 3; i++) {

if (theSame = 0) could be if (!theSame)

i = 1.5; 1.5 isn't an int, what were you trying to do here?

IHBT

Name: Anonymous 2008-03-15 21:20

>>6
if (theSame = 0)
=

Name: Anonymous 2008-03-15 21:32

Ok so now im getting an error Ive never got before. "size has private access in java.util.ArrayList" In the line "tempSize = list.size;"

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

public class MyArray{  
static ArrayList copy;  


     public static void main()     {
        int i=0, thesame, size;         
       
        ArrayList<String> list = new ArrayList<String>();
        
         String bString = "done";
         for(i=0;i<0;i++){
             System.out.println("Enter a name");
             Scanner input = new Scanner(System.in);
              String nextWord = input.next();
              list.add(i,nextWord);
              boolean theSame = bString.equals("Done");
              if(theSame = true)
                  i = -1;
         }   
          size = list.size();
          for(i=0;i<=0;i++){
              String temp = ((String)copy.get(i));
              System.out.print(temp);
            }  
               
               
    }
    public ArrayList sort(ArrayList list){
      
        int top, i, maxIdx, copy1, tempSize;
       
       
        ArrayList<String> copy = new ArrayList<String>(list.size());
        tempSize = list.size;
    for (i = 0;i < tempSize;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-15 21:41

tempSize = list.size();

Name: Anonymous 2008-03-15 21:43

god damnit, im retarded, thanks

Name: Anonymous 2008-03-15 21:59

>>10
That'll be the new /prog/ slogan.

Name: Anonymous 2008-03-15 22:04

ok so thanks for the help guys, but i have one final predicament, so i finally got it all debugged with no syntax errors, but now when i run it, it immediately closes and says null pointer exception and the line "String temp = ((String)copy.get(i));" is highlighted, never had this happen before either

Name: Anonymous 2008-03-15 22:06

>>11
'-._                  ___.....___
    `.__           ,-'        ,-.`-,
        `''-------'          ( X )  `._     god damnit,
                              `-'      (    i'm retarded,
                                        \   thanks
                                        \
                               ,...''-..'
   ................._         /,..-''..,
                     `-.._         _.-'
                          `'-----''

Name: Anonymous 2008-03-15 22:07

>>12
null pointer exception
Learn to troll.

Name: Anonymous 2008-03-15 22:07

>>14
?

Name: Anonymous 2008-03-15 22:10

>>12
because copy hasn't been initialized at that point, it's null

Name: Anonymous 2008-03-15 22:15

>>16
but since i returned it in the sort method shouldnt it be good to go?

Name: Anonymous 2008-03-15 22:20

you never called the sort method, add sort(list); after size = list.size(); and before the for loop

Name: Anonymous 2008-03-15 22:23

i meant copy = sort(list);

Name: Anonymous 2008-03-15 22:43

[i]ENTERPRISE[/o]

Name: Anonymous 2008-03-15 23:34

ok well now i think im understanding this better, but now im getting an illegal start of expression for the beginning line of my sort method, why is this happening after adding the new line?

Name: Anonymous 2008-03-15 23:56

your brackets might be messed up

Name: Anonymous 2008-03-16 0:53

Go to http://www.meatspin.com/

There, you will find the answer.

Name: Anonymous 2008-03-16 7:38

>>23
back to /b/, please

Name: Anonymous 2008-03-16 13:12

ok expert programmers, after a couple more hours of debugging it seems ive hit another wall, now again I have no more syntax errors but when trying to run it it comes back and says out of bounds error on the line "String temp = ((String)copy.get(i));" which i think it probably means is trying to access the first slot of the array list but there is nothing there which i dont get because ive created the sort method and then called it. But it wont even let me input anything before it closes which is probably why there isnt anything there, here is the new code


import java.util.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);
         String bString = "done";
         for(i=0;i<0;i++){
             System.out.println("Enter a name");
            
              String nextWord = input.next();
              list.add(i,nextWord);
              boolean theSame = bString.equals("Done");
              if(theSame = true)
                  i = -1;
                }
                  size = list.size();
                ArrayList copy = sort(list);
          for(i=0;i<=copy.size();i++){
              String temp = ((String)copy.get(i));
              System.out.print(temp);
         }   
               
   
}
    public  static ArrayList sort(ArrayList list){
      
        int top, v, maxIdx,  tempSize,size;
       
       
        ArrayList<String> copy = new ArrayList<String>(list.size());
        tempSize = list.size();
    for (v = 0;v < tempSize;v++)
        copy.add((String)list.get(v));
    for ( top=copy.size()-1;top > 0;top--) {
        String maximum = ((String)copy.get(0));
        maxIdx = 0;

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

}


Name: Anonymous 2008-03-16 14:41

also sorry for the bad indentation

Name: Anonymous 2008-03-16 15:07

This is such an obvious troll.

I hereby declare this thread over. Thank you for your cooperation.

Name: Anonymous 2008-03-16 15:10

>>27
Only FIOC can declare a thread over.

Name: Anonymous 2008-03-16 15:19

>>27
jesus, as i said im really crappy at this, im trying not to sound so stupid, I have been doing this program forever but i dont understand why im getting an out of bounds exception now, jesus im sorry im not a professional quality programmer, im not saying you have to help me but im not a troll, just retarded when it comes to comp sci i guess

Name: Anonymous 2008-03-16 15:24

op here again, there is probably just one simple concept or something I am missing, correct? I'm sure once i figure this out I will understand much better.

Name: Anonymous 2008-03-16 15:26

>>29
Why should I believe a troll? gb2trollland, troll.

Name: Anonymous 2008-03-16 15:26

>>29
professional quality programmer
Proprietary customer-oriented solutions

Name: Anonymous 2008-03-16 15:29

Established in 1997, Enterprise Solutions is 100% focused in providing customers with the best infrastructure solutions available in the marketplace. We architect, design, supply, install and maintain scalable enterprise solutions within your required timescales and budget to enable your business to grow.

Name: Anonymous 2008-03-16 15:30

Enterprise Solutions can design, maintain, upgrade and support solutions that enable you to centralise the management and storage of your information. As the volume, complexity and importance of your data increases, Enterprise Solutions can also provide you with seamless scalable solutions to manage and protect new elements without the need to upgrade your infrastructure, all at a fraction of the time, effort and expenditure required by simply implementing separate products.

Name: Anonymous 2008-03-16 16:57

Well thanks for the help anyways guys, ill just keep fiddling with it i guess

Name: Anonymous 2008-03-16 17:12

Try stabbing yourself in the chest. I've heard that works.

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.

Name: Anonymous 2008-03-16 20:22

>>37
oh wow, some of those mistakes are just retarded on my part, i was writing this at like 3 in the morning yesterday, thanks though ill keep working from there

Name: Anonymous 2008-03-16 20:25

Jeez, you can't even write English properly.

Name: Anonymous 2008-03-16 20:43

>>39
cry some more

Name: Anonymous 2008-03-16 20:46

>>40
Post some more of your code and I just might.

Name: Anonymous 2008-03-16 20:48

Op here, I think I might actually switch my major to something that will actually land me a decent job that actually pays good, requires good social skills and strong math, and doesn't have the shit being outsourced out of it.

Name: Anonymous 2008-03-16 20:48

Please do!

Name: Anonymous 2008-03-16 20:53

op here
>>42
was not me,
also fuck off, i dont give a damn about my english on 4chan. but i do agree with 42 as well in some aspects,

Name: Anonymous 2008-03-16 20:54

Well, I care. And that's all that matters.

Name: Anonymous 2008-03-16 20:56

This is the cancer that's killing /prog/.

Name: Anonymous 2008-03-16 20:57

>>45
>>46
cry some more

Name: Anonymous 2008-03-16 20:58

>>44
also fuck off, i dont give a damn about my english on 4chan.
lrn2shibboleth, cancermonkey.

Name: Anonymous 2008-03-16 20:59

>>47
You're very close to angering me. I suggest you take a step back and reflect, son.

Name: Anonymous 2008-03-16 21:01

op here
>>47
was not me again

Name: Anonymous 2008-03-16 21:01

op here
disregard that i sucks teh cocks

Name: Anonymous 2008-03-16 21:02

There are two people on /prog/ who know enough Java to help you. Fuqin angering them isn't in your best interest.

In other words, back to /b/, please.

Name: Anonymous 2008-03-16 21:04

/prog/ has been dead for a while now, seriously, its a programming board, the place where the cancer killing society(i.e. socially retarded fatasses who contribute little to the world) can gather and feel the illusion of being elite some how, yes op the comp sci industry is a joke at the moment and probably for a LONG time, you will get an entry level programming job and go nowhere, i suggest if you are good with the math just major in math and go into high level finances, work for big coorperations or something, if you are indeed good at math and have reasonable social skills you can pull it off, steer clear the of comp sci for now though, take it as an elective if you want, i dont think you suck at programming, i mean ya you do, but everyone does when they start

Name: Anonymous 2008-03-16 21:05

>>52
op here, as i said im not the one being a douchebag, those people arent me

Name: Anonymous 2008-03-16 21:05

tl,dr

Name: Anonymous 2008-03-16 21:06

>>54
Stop being a douchebag. Douchebag.

Name: Anonymous 2008-03-16 21:09

Op here, I loved my last comp sci class as it was based in c++. I was great at it and I ended up with an A in the class, but so far java just seems like a pain in the ass language that has no benefit unless i want to make little faggy applets, of course since im new at this im probably wrong but it just seems that way right now which is really turning me off from computer science

Name: Anonymous 2008-03-16 21:09

>>53
Inb4 nobody responds to this because they are scared of the truth

Name: Anonymous 2008-03-16 21:13

>>58
we know that it is true, but i do it for the passion of programming, ya I probably will never make too too great of money but I love to program and thats all that matters

Name: Anonymous 2008-03-16 21:13

>>57
If you approach Java like Sepples you're going to suck royally at it. It may not be perfectly OO, but it's still a fuck of a lot more OO than Sepples, and it requires a different style of programming.
Though the mistakes in the code posted here are so very basic and not specific to Java I doubt OP has ever programmed in anything except maybe BASIC.

>>58
Read the FUCKING HATE REDDIT thread. I don't feel like repeating myself.

Name: Anonymous 2008-03-17 3:32

>>57
Applets are so last century ...
The only reason for doing anything with Java is that the GUI programming is far less of a PITA than it is in C++

Nowadays with Jython/JRuby/Groovy/Scala...  running on the JVM, it doesn't have even that advantage, since they all call into the same APIs

Name: Anonymous 2009-03-06 7:37

The file you could   try some hackery   involving the overloaded.

Name: Anonymous 2009-07-02 21:58

How deliciously enterprise.

Name: Anonymous 2010-12-17 1:27

Xarn is a bad boyfriend

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