ArrayList help

ok still having trouble, i redid alot of the program, i need to slim down the ArrayList to being one instance of a word per file, plus all of the lines they are on inside that one instance. Right now there are mulitple instances of each word and each one has its own line its on. I have tried for the past 3 hours trying to get this to work, anything from finding a way to sort it then compair first and last index's to moving them to arrays and manually doing it. I just cant figure this out any help would be great!
just for refrance the arguement taken is a text file that lists other text files which have plain text in them
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
class FileParser
     static ArrayList files = new ArrayList();
     JFrame frame = new JFrame("Search Engine v1.0");
     JTextField text = new JTextField(20);
     JTextArea display = new JTextArea(20,20);
     int xPosition;
     int yPosition;
     static int testCounter = 0;
     FileObj fo;
     //ArrayList <Word>finalWord = new ArrayList<Word>();
     public static void main(String[] args)
          FileParser fp = new FileParser(args[0]);
          fp.GUI(); disabling GUI for now
     public FileParser(String s)
          String option = "";
          try
               BufferedReader br = new BufferedReader(new FileReader(s));
               String inLine = br.readLine();
               while(inLine != null)
                    FileObj fo = new FileObj(inLine);
                    fo.processFile();
                    files.add(fo);
                    inLine = br.readLine();
                    System.out.println("test");
               br.close();//the arraylist files now has each file name that containes words
               System.out.println(files);
          catch(IOException e){}
     public void GUI()
          Container con;
          JLabel l1;
          JPanel top, middle, bottom;
          con = frame.getContentPane();
          con.setLayout(new BorderLayout());
          top = new JPanel(new GridLayout(1,3));
          middle = new JPanel(new GridLayout(2,1));
          bottom = new JPanel(new GridLayout(1,3));
          top.add(new JLabel("Search for:"));
          top.add(text);
          middle.add(new JLabel("Results: "));
          middle.add(new JScrollPane(display));
          JButton search = new JButton("Search");
          search.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
               //System.out.println(text.getText());
               FileObj.list(text.getText());
          JButton clear = new JButton("Clear");
          clear.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
               text.setText("");
               display.setText("");
          JButton exit = new JButton("Exit");
          exit.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent e)
               System.exit(0);
          bottom.add(search);
          bottom.add(clear);
          bottom.add(exit);
          con.add(top, BorderLayout.NORTH);
          con.add(middle, BorderLayout.CENTER);
          con.add(bottom, BorderLayout.SOUTH);
          frame.setSize(400, 250);
          frame.setVisible(true);
import java.util.*;
import java.io.*;
class FileObj
     String fileName;
     int wordCount;
     int uniqueWords;
     int lineCount;
     ArrayList <Word>words = new ArrayList<Word>();
     Boolean first = true;
     FileObj(String theFiles)
          fileName = theFiles;//individual file name
          System.out.println(fileName);
     public void processFile()
          FileReader infile = null;//helps load files text for reading
          StreamTokenizer reader = null;//helps tokenizes the files text
          int testCounter = 0;
          try
               infile = new FileReader(fileName);//finishes loading files text
               reader = new StreamTokenizer(infile);//finishes tokenizing files text
               reader.wordChars(65, 122);//tells it to only take letters
               reader.nextToken();
               while (reader.ttype != reader.TT_EOF)// while the end of the stream hasnt been reached
                    if (reader.ttype == reader.TT_WORD)//if the stream has read a token
                         String token = reader.sval;//creates a string with the token in it
                         wordCount++;
                         token = stripWord(token);//strips token of non letters
                         processWord(token, reader.lineno(), fileName);
                    reader.nextToken();
                    lineCount = reader.lineno();// gets me the line number
               exists();
               testCounter = words.size();
               for(int i = 0; i<testCounter;i++)
                    System.out.println(words.get(i));
               infile.close();
               //try to print out a search
          catch(FileNotFoundException e){}
          catch(IOException e){}
     public String toString()
          return ("FileName: "+fileName+" WordCount: "+wordCount+" UniqueWords:"+uniqueWords+" LineCount: "+lineCount);
     public String stripWord(String w)
          w = w.replace('.',' ');
     w = w.replace(',',' ');
     w = w.replace('?',' ');
     w = w.replace(':',' ');
     return w.trim().toUpperCase();
     public void processWord(String s, int line, String f)
          Word wordObj = new Word(s, line, f);
          words.add(wordObj);
          (words);
        public void exists()// this is only to find if the word exists
          int arrayCounter= 0;
          //words
     }     public static String list(String w)
          System.out.println("do i see this?");
          return w;
/* Word wordObj = finalWord.get(w.toUpperCase());
if (wordObj != null)
System.out.println(w + " found in " + fileName + " at lines " + wordObj.lineNumbers.toString());
import java.util.*;
class Word
     String value;
     String fileName;
     int count;
     ArrayList lineNumbers;
     public Word(Word wordCopy)
          value = wordCopy.value;
          fileName = wordCopy.fileName;
          count = wordCopy.count;
          lineNumbers = wordCopy.lineNumbers;
     public Word(String v, int l, String f)
          value =v;
          fileName = f;
          lineNumbers = new ArrayList();
          lineNumbers.add(new Integer(l));
          count++;
          //System.out.println("god i hope i see the unique words, this is one: "+value+" "+lineNumbers);
     public Word(String v)
          value = v;
     public void update(int l)
          lineNumbers.add(new Integer(l));
          count++;
     public String toString()
          return "FileName:"+fileName+" Word:"+value+" Lines found in: "+lineNumbers;
     public String getWord()
          return value;
     public int getEverything()
          int size = count;
          return size;
     public boolean compairTo(String s1)
          if(value.equals(s1))
               return true;
          else
               return false;
}

ok i put it all inside code brackets, i was told you only the part i was having trouble with. But i explained what the program does and im just trying to get the ArrayList which is filled with my Word objects to become sorted kind of. Right now it will have multiple instances of exact words, but they will be on diffrent lines, i need to shorten it down and put the lineNumbers all into the same word object if they are the same String value.import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.io.*;
class FileParser
static ArrayList files = new ArrayList();
JFrame frame = new JFrame("Search Engine v1.0");
JTextField text = new JTextField(20);
JTextArea display = new JTextArea(20,20);
int xPosition;
int yPosition;
static int testCounter = 0;
FileObj fo;
//ArrayList <Word>finalWord = new ArrayList<Word>();
public static void main(String[] args)
FileParser fp = new FileParser(args[0]);
fp.GUI(); disabling GUI for now
public FileParser(String s)
String option = "";
try
BufferedReader br = new BufferedReader(new FileReader(s));
String inLine = br.readLine();
while(inLine != null)
FileObj fo = new FileObj(inLine);
fo.processFile();
files.add(fo);
inLine = br.readLine();
System.out.println("test");
br.close();//the arraylist files now has each file name that containes words
System.out.println(files);
catch(IOException e){}
public void GUI()
Container con;
JLabel l1;
JPanel top, middle, bottom;
con = frame.getContentPane();
con.setLayout(new BorderLayout());
top = new JPanel(new GridLayout(1,3));
middle = new JPanel(new GridLayout(2,1));
bottom = new JPanel(new GridLayout(1,3));
top.add(new JLabel("Search for:"));
top.add(text);
middle.add(new JLabel("Results: "));
middle.add(new JScrollPane(display));
JButton search = new JButton("Search");
search.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
//System.out.println(text.getText());
FileObj.list(text.getText());
JButton clear = new JButton("Clear");
clear.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
text.setText("");
display.setText("");
JButton exit = new JButton("Exit");
exit.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
bottom.add(search);
bottom.add(clear);
bottom.add(exit);
con.add(top, BorderLayout.NORTH);
con.add(middle, BorderLayout.CENTER);
con.add(bottom, BorderLayout.SOUTH);
frame.setSize(400, 250);
frame.setVisible(true);
import java.util.*;
import java.io.*;
class FileObj
String fileName;
int wordCount;
int uniqueWords;
int lineCount;
ArrayList <Word>words = new ArrayList<Word>();
Boolean first = true;
FileObj(String theFiles)
fileName = theFiles;//individual file name
System.out.println(fileName);
public void processFile()
FileReader infile = null;//helps load files text for reading
StreamTokenizer reader = null;//helps tokenizes the files text
int testCounter = 0;
try
infile = new FileReader(fileName);//finishes loading files text
reader = new StreamTokenizer(infile);//finishes tokenizing files text
reader.wordChars(65, 122);//tells it to only take letters
reader.nextToken();
while (reader.ttype != reader.TT_EOF)// while the end of the stream hasnt been reached
if (reader.ttype == reader.TT_WORD)//if the stream has read a token
String token = reader.sval;//creates a string with the token in it
wordCount++;
token = stripWord(token);//strips token of non letters
processWord(token, reader.lineno(), fileName);
reader.nextToken();
lineCount = reader.lineno();// gets me the line number
exists();
testCounter = words.size();
for(int i = 0; i<testCounter;i++)
System.out.println(words.get(i));
infile.close();
//try to print out a search
catch(FileNotFoundException e){}
catch(IOException e){}
public String toString()
return ("FileName: "+fileName+" WordCount: "+wordCount+" UniqueWords:"+uniqueWords+" LineCount: "+lineCount);
public String stripWord(String w)
w = w.replace('.',' ');
w = w.replace(',',' ');
w = w.replace('?',' ');
w = w.replace(':',' ');
return w.trim().toUpperCase();
public void processWord(String s, int line, String f)
Word wordObj = new Word(s, line, f);
words.add(wordObj);
(words);
     public void exists()// this is only to find if the word exists
          int arrayCounter= 0;
          //words
public static String list(String w)
System.out.println("do i see this?");
return w;
/* Word wordObj = finalWord.get(w.toUpperCase());
if (wordObj != null)
System.out.println(w + " found in " + fileName + " at lines " + wordObj.lineNumbers.toString());
import java.util.*;
class Word
String value;
String fileName;
int count;
ArrayList lineNumbers;
public Word(Word wordCopy)
value = wordCopy.value;
fileName = wordCopy.fileName;
count = wordCopy.count;
lineNumbers = wordCopy.lineNumbers;
public Word(String v, int l, String f)
value =v;
fileName = f;
lineNumbers = new ArrayList();
lineNumbers.add(new Integer(l));
count++;
//System.out.println("god i hope i see the unique words, this is one: "+value+" "+lineNumbers);
public Word(String v)
value = v;
public void update(int l)
lineNumbers.add(new Integer(l));
count++;
public String toString()
return "FileName:"+fileName+" Word:"+value+" Lines found in: "+lineNumbers;
public String getWord()
return value;
public int getEverything()
int size = count;
return size;
public boolean compairTo(String s1)
if(value.equals(s1))
return true;
else
return false;

Similar Messages

  • ArrayList help indexing a string

    Basically for this project, I need the user to input a sentence and then i have to print out the different words with their index.
    For example if the user inputs the following:
    Hello Hello Hello World World World Hello
    The program should output:
    Hello 0, 1, 2, 6
    World 3,4,5
    something in that range well so i attempted this and here is my code:
    import java.util.*;
    public class Check
         public static void main(String[] args)
              String word = "";
               ArrayList <String> diffWord = new ArrayList<String>();
               ArrayList <Integer> spaces = new ArrayList<Integer>();
              ArrayList <String> noRepeat = new ArrayList<String>();
               ArrayList <String> everyThing = new ArrayList<String>();
               String everything = "";
               String total = "";
               String toString = "";
              Scanner scan = new Scanner (System.in);
             String sentence = "";
             // get the string
             System.out.println("Please enter a sentence without any capitals or puntuation marks");
             sentence = scan.next();
             // get the index for spaces
             for (int i = 0; i< sentence.length(); i++)
                   if(sentence.charAt(i)==(' '))
                        spaces.add(i);
              // get the different words in Sentence
              for (int i = 0; i< sentence.length(); i++)
                   word = sentence.substring(spaces.get(i)+1,spaces.get(i+1));
                   diffWord.add(word);
              // get position of each word
              for (int i = 0; i < diffWord.size(); i++)
                   for (int j = 0; j < diffWord.size(); j++)
                        if (diffWord.get(i)!= (noRepeat.get(i)))
                             noRepeat.add(diffWord.get(i));
              //  get everything in one
              for(int i = 0; i < noRepeat.size(); i++)
                   for (int j = 0; j < diffWord.size(); j++)
                        if (noRepeat.get(i).equals(diffWord.get(j)))
                             everything += (i+" ");
                             total = (noRepeat.get(1)+ " "+everything);
                             everyThing.add(total);
              // print out everything
              for (int i = 0; i < everyThing.size(); i++)
                   toString +=  everyThing.get(i);
              System.out.println(toString);
    }it compiles fine but after the sentence is inputted i get the following error:
    Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.RangeCheck(ArrayList.java:546)
        at java.util.ArrayList.get(ArrayList.java:321)
        at DocumentIndex.getDiffWord(DocumentIndex.java:38)
        at IndexMaker.main(IndexMaker.java:17)
    Process completed.Can someone PLEASE help me??? I'v been stuck on the same project for the past 4 hours and none of my friends seem to understand what to do...

    U can try like this.......
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.util.*;
    public class Check
         public static void main(String[] args)
              try{
              String word = "";          
               String everything = "";
               String total = "";
               String toString = "";
               String sentence = "";
             // get the string
             System.out.println("Please enter a sentence without any capitals or puntuation marks");
             BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
             sentence=in.readLine();  
              // get the different words in Sentence
             String s[] = sentence.split(" ");     
             Hashtable ht=new Hashtable();  
                   for (int i = 0; i< s.length; i++)
                        if(ht!=null)
                             if(!ht.containsKey(s))                              
                                  ht.put(s[i],new Integer(i+1).toString());
                             else
                                  Object ob=ht.get(s[i]);
                                  String str=(String)ob;
                                  str=str+" "+new Integer(i+1).toString();                              
                                  ht.remove(s[i]);
                                  ht.put(s[i],str);
                   Enumeration e = ht.keys();               
              //iterate through Hashtable keys Enumeration
              while(e.hasMoreElements())
                   String temp=e.nextElement().toString();
              System.out.print(temp+ " ");
              System.out.println(ht.get(temp));
              catch (Exception e) {
                   // TODO: handle exception
                   e.printStackTrace();
                   System.out.println(e.toString());
    hope this will help
    Thanks
    Nicky                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How import relations of a model in Web Dynpro project

    I am importing a bean as model in my webdynpro project.
    This bean is having a List(customerList) and a currosponding getter method. This List will become a relation. Can anybody tell me how to use this relation in my Webdynpro project when I import this bean as a model to my project?

    Hi
    I am having both the TestBean and HelperBean in the same package. Below is the code of TestBean. This bean is in turn calling HelperBean ,which is returning a List. I am importing both these beans in model but still I am getting an error while creating model -
    <b>[Error]:     There are one or more relations unresolved. Importing the model without resolvoing the relations might result in erratic output.</b>
         public class TestBean implements Serializable{
         private List customerList= null;
         HelperBean helper = new HelperBean();
              public void execute(){
              try{
                                            customerList = (ArrayList)helper.getCustomerList();
                   catch(Exception ex){
                        ex.printStackTrace();
          * @return
         public List getCustomerList() {
              return customerList;
          * @param list
         public void setCustomerList(List list) {
              customerList = list;
    Please inform if there is some solution.
    regards,
    Sujit

  • Dynamic checkboxes with jsp

    Hi,
    I need to create dynamic checkboxes in my jsp page from the values retrived from the database(oracle).help me with the code.My oracle queries are in my Java bean coding.pls its very very urgent.help me out.

    hi,
    This is my bean coding.can u pls tell me how to store the resultset values in a arraylist.help me out.
    package campaign;
    //Imports
    import java.io.*;
    import javax.sql.DataSource;
    import javax.naming.*;
    import com.ibm.ws.sdo.mediator.jdbc.Create;
    import java.sql.*;
    * @author n48edf
    * TODO To change the template for this generated type comment go to
    * Window - Preferences - Java - Code Style - Code Templates
    public class AgentDao extends java.lang.Object implements UnsubscribeConstants
    protected int indivID = 0;
    protected Connection _conn;
    protected DataSource ds = null;
    protected ResultSet rs = null;
    private String driver = null;
    //need to code
    public void agentLoad(IndvId) throws IOException
    String driver = ORACLE_DRIVER;
    String dataSource= ORACLE_DATA_SOURCE;
    try
    //Establish database connection
    if (_conn == null)
    try
    Context context = new InitialContext();
    // JDBC JNDI lookup
    ds = (DataSource)context.lookup(dataSource);
    context.close();
    // Get a connection
    _conn = ds.getConnection();
    catch (Exception exp)
    throw exp;
    // Create a connection statement
    Statement stmt = _conn.createStatement();
    rs = stmt.executeQuery("SELECT DISTINCT busn_org_nm "+
    "FROM BUSN_ORG bo,AGYLOCINDV_RESP_BUSORG ab "+
    "WHERE ab.busn_org_cd=bo.busn_org_cd AND ab.indvid=p_IndvId");
    String array[]=rs;
    stmt.close();
    cleanUp();
    catch ( SQLException sqe )
    System.out.println ("AgentDao.java - SQL Exception: " + sqe.toString());
    sqe.printStackTrace();
    catch ( Exception e )
    System.out.println ("AgentDao.java - Exception: " + e.toString());
    e.printStackTrace();
    finally
    if(_conn != null|| rs != null)
    cleanUp();
    public void cleanUp()
    try
    //close resultset
    if (rs != null)
    rs.close();
    rs = null;
    //close connection
    if(_conn != null)
    _conn.close();
    _conn = null;
    catch (SQLException sqe)
    System.out.println("SQL Exception occurred in cleanUp() of AgentDAO");
    sqe.printStackTrace();
    catch (Exception e)
    System.out.println("Error occurred in cleanUp() of AgentDAO");
    e.printStackTrace();
    }

  • How to deal with relation

    Hi
    I am trying to import two beans(TestBean and HelperBean)into my Web Dynpro project to create a model. These beans are dealing with a List(ArrayList). This List is considered as a Relation. I am facing problem in handling this relation.
    I am having both the TestBean and HelperBean in the same package. Below is the code of TestBean. This bean is in turn calling HelperBean ,which is returning a List.
    I am getting an error while creating model -
    <b>[Error]: There are one or more relations unresolved. Importing the model without resolvoing the relations might result in erratic output.</b>
    <u><b>Code For TestBean</b></u>
    public class TestBean implements Serializable{
         private List customerList= null;
         HelperBean helper = new HelperBean();
              public void execute(){
              try{
                                            customerList = (ArrayList)helper.getCustomerList();
                   catch(Exception ex){
                        ex.printStackTrace();
          * @return
         public List getCustomerList() {
              return customerList;
          * @param list
         public void setCustomerList(List list) {
              customerList = list;
    I am new to Web Dynpro and don't know how to deal with relation.Please inform if there is some solution.
    regards,
    Sujit

    Sujit,
    Not every bean becomes model class during import. So your HelperBean is irrelevant here. But you miss other bean, namely Customer bean. You must add it as model class during import, then select problematic 0..n relation and resolve it to model class Customer.
    Valery Silaev
    SaM Solutions
    http://www.sam-solutions.net

  • Help with ArrayList...

    Hi Everyone:
    I have this java program that I'm doing for school and I need a little bit of insite on how to do certain things. Basically what I did was I read a text file into the program. Once I tokenized the text(by line), I created another object(we'll call it Throttle) and passed the values that was tokenized, then I stored the object(Throttle) into ArrayList. Now, my question is how to I access the object(Throttle) from the ArrayList and use the object's(Throttle) methods? Here's the code that I have currently:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class Project1 extends JFrame
    private JButton numOfThrottles, shiftThrottle, createThrottle, quit;
    private JPanel panel;
    private FileReader fr;
    private BufferedReader br;
    private FileWriter fw;
    private int tempTop;
    private int whatToShift;
    private int tempPosition;
    private ArrayList arrThrottles = new ArrayList();
    private String line;
    private Throttle myThrottle = null, daThrottle;
    private StringTokenizer st;
    public Project1()
    super ("Throttles - by Joe Munoz");
    panel = new JPanel();
    setContentPane(panel);
    panel.setLayout(null);
    //**button stuff
    numOfThrottles = new JButton("Number of Throttles");
    shiftThrottle = new JButton("Shift a Throttle");
    createThrottle = new JButton("Create New Throttle");
    quit = new JButton("Quit");
    panel.add(numOfThrottles);
    panel.add(shiftThrottle);
    panel.add(createThrottle);
    panel.add(quit);
    numOfThrottles.setBounds(5,7,150,25);
    shiftThrottle.setBounds(5,30,150,25);
    createThrottle.setBounds(5,50,150,25);
    quit.setBounds(5,70,150,25);
    numOfThrottles.addActionListener(new ClickDetector());
    shiftThrottle.addActionListener(new ClickDetector());
    createThrottle.addActionListener(new ClickDetector());
    quit.addActionListener(new ClickDetector());
    //window stuff
    setSize(170,135);
    show();
    try
    br = new BufferedReader(new FileReader("C:\\Storage.txt"));
    catch (FileNotFoundException ex)
    System.out.println ("File Not Found!");
    try
    line = br.readLine();
    while (line != null)
    st = new StringTokenizer(line, " ");
    tempTop = Integer.parseInt(st.nextToken());
    tempPosition = Integer.parseInt(st.nextToken());
    myThrottle = new Throttle(tempTop, tempPosition);
    arrThrottles.add(myThrottle);
    line = br.readLine();
    catch(Exception e)
    System.out.println("IO Exception!!!");
    System.exit(0);
    private class ClickDetector implements ActionListener
    public void actionPerformed(ActionEvent event)
    try
    if (event.getSource() == numOfThrottles)
    JOptionPane.showMessageDialog(null, "Number of Throttles is..." + myThrottle.getNumOfThrottles());
    if (event.getSource() == shiftThrottle)
    String shift = JOptionPane.showInputDialog("Please Choose a Throttle from 0 to " + (arrThrottles.size() - 1));
    whatToShift = Integer.parseInt(shift);
    System.out.println ("whatToShift = " + whatToShift);
    // Need help here
    if (event.getSource() == createThrottle)
    String inTop = JOptionPane.showInputDialog("Please Enter Top");
    tempTop = Integer.parseInt(inTop);
    String inPosition = JOptionPane.showInputDialog("Please Enter Position");
    tempPosition = Integer.parseInt(inPosition);
    myThrottle = new Throttle(tempTop, tempPosition);
    arrThrottles.add(myThrottle);
    JOptionPane.showMessageDialog(null, "The Throttle has been created");
    if (event.getSource() == quit)
    System.out.println ("you clicked quit");
    catch (Exception e)
    JOptionPane.showMessageDialog(null, "No Numbers inputted!");
    Any insite/suggestions on what to do? Thank You.
    Joe

    Hi,
    I have a question addition to this same question.
    If you have an object and there are 10 different objects with in the object ..
    tempTop = Integer.parseInt(st.nextToken());
    tempPosition = Integer.parseInt(st.nextToken());
    tempBottom = 10;
    Is this how you access( from the same example) each object value
    strTop= (Throttle)arrThrottles.get(i).tempTop;
    strPos= (Throttle)arrThrottles.get(i).tempPosition;
    strB= (Throttle)arrThrottles.get(i).tempBottom;
    ----I AM USING ARRAYS in a JAVABEAN
    Class test {
    public objectTEMP t[] = null;
    public void initialize(val1,al2) {
         t = redim(t,10,false); //To set the length of the array to 10
    public class T {
    String s1 = null;
    String s2 = null;
    int i1 = null;
    public void setS1(String inVal) {
              s1=inVal;
    public void setS2(String inVal) {
         s2=inVal;
    public void setI1(int inVal) {
         i1=inVal;
    public String getS1() {
              return s1;
    public String getS2() {
              return s2;
    public String getI1() {
              return i1;
    for (int i=0; i<t.length;i++) {
    System.out.println("t"+i+t.getS1());
    t.setS1("SOMESTRING");
    System.out.println("t"+i+t.getS1());
    Any use the setter and getter method from JSP to update or get the information.
    I want to change this to ArrayList as they are fast and they have resizing ability.
    How to I implement this in ARRAYLIST.
    Thanks a bunch

  • Calling arraylist from another class - help please!!

    Hey, I need some help calling my arraylist from my GUI class, as the arraylist is in the 'AlbumList' class and not in the 'GUI' class i get the error 'cannot find symbol', which is pretty obvious but i cannot figure how to get around this problem. help would be greatly appreciated.
    i have written ***PROBLEM*** next to the bad line of code!
    Thanks!!
    public class Album
        String artist;
        String title;
        String genre;
        public Album(String a, String t, String g)
            artist = a;
         title = t;
            genre = g;
         public String getArtist()
            return artist;
        public String getTitle()
            return title;
         public String getGenre()
            return genre;
    public class AlbumList
        public ArrayList <Album> theAlbums;
        int pointer = -1;
        public AlbumList()
            theAlbums = new ArrayList <Album>();
        public void addAlbum(Album newAlbum)
         theAlbums.add(newAlbum);
    import java.util.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class GUI extends JFrame
        public int max = 5;
        public int numAlbums = 4;
        public int pointer = -1;
        public GUI ()
            super("Recording System");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel main = new JPanel();
            JPanel panel1 = new JPanel();
            panel1.setLayout(new GridLayout(3,2,0,0));
            JPanel panel2 = new JPanel();
            panel2.setLayout(new GridLayout(1,2,20,0));
            final JLabel artistLBL = new JLabel("Artist: ");
            final JLabel titleLBL = new JLabel("Title: ");
            final JLabel genreLBL = new JLabel("Genre: ");
            final JTextField artistFLD = new JTextField(20);
            final JTextField titleFLD = new JTextField(20);
            final JTextField genreFLD = new JTextField(20);
            final JButton nextBTN = new JButton("Next");
            nextBTN.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    pointer++;
                    artistFLD.setText(theAlbums.get(pointer).getArtist());       ***PROBLEM***
                    titleFLD.setText("NEXT");
                    genreFLD.setText("NEXT");
            final JButton prevBTN = new JButton("Prev");
            prevBTN.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    pointer--;
                    artistFLD.setText("PREVIOUS");
                    titleFLD.setText("PREVIOUS");
                    genreFLD.setText("PREVIOUS");
         panel1.add(artistLBL);
            panel1.add(artistFLD);
            panel1.add(titleLBL);
            panel1.add(titleFLD);
            panel1.add(genreLBL);
            panel1.add(genreFLD);
            panel2.add(prevBTN);
            panel2.add(nextBTN);
            main.add(panel1);
            main.add(panel2);
            setVisible(true);
            this.getContentPane().add(main);
            setSize(500, 500);
    -----------------------------------------------------------------------Thanks!!
    Edited by: phreeck on Nov 3, 2007 8:55 PM

    thanks, it dosnt give me a complication error but when i press the button it says out of bounds error, and i think my arraylist may be empty possibly even though i put this data in.. this is my test file which runs it all.
    any ideas? thanks!!
    public class Test
        public static void main(String []args)
            AlbumList a = new AlbumList();
            String aArtist = "IronMaiden";
            String aTitle = "7thSon";
            String aGenre = "HeavyMetal";
            Album newA = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newA);
            aArtist = "LambOfGod";
            aTitle = "Sacrament";
            aGenre = "Metal";
            Album newB = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newB);
            aArtist = "JohnMayer";
            aTitle = "Continuum";
            aGenre = "Guitar";
            Album newC = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newC);
            aArtist = "StillRemains";
            aTitle = "TheSerpent";
            aGenre = "Metal";
            Album newD = new Album(aArtist, aTitle, aGenre);
            a.addAlbum(newD);
         GUI tester = new GUI();
    }

  • Cry for HELP!! -- ArrayList NullPointerException Error

    All,
    I keep getting a NullPointerException error when I attempt to add an object to an ArrayList. I have debugged in every possible place. The transfer of data between servlets and classes is good, because I'm printing them out to System.out (for debug purposes)... but adding the instantiated object to the arraylist keeps throwing NullPointer Error. Please review codes to help me determine error. I just can't figure this out! And this is due yesterday. Pls help!!!!
    the class Code:
    ===================================================
    import java.util.ArrayList;
    import java.lang.Long;
    import java.lang.Double;
    public class CellieRator
    public CellieRator()
    (just attributes initializations here. didn't initialize arraylist to null)
    ArrayList myfactors;
    class FactorsList
    long div;
    double safeCred;
    double ccp;
    double incLimit;
    double deductibleCredit;
    double schedDebCred;
    double drugCred;
    double ppdiscount;
    double waiversubrogation;
    double expenseconstant;
    double tria;
    double dtec;
    FactorsList()
    public void addMyFactors(long divin, Double safeCredin, Double ccpin, Double incLimitin, Double deductibleCreditin, Double schedDebCredin, Double drugCredin, Double ppdiscountin, Double waiversubrogationin, Double expenseconstantin, Double triain, Double dtecin)
    FactorsList fl = new FactorsList();
    fl.div = divin;
    fl.safeCred = safeCredin != null ? safeCredin.doubleValue() : 0.0;
    fl.incLimit = incLimitin != null ? incLimitin.doubleValue() : 0.0;
    fl.deductibleCredit = deductibleCreditin != null ? deductibleCreditin.doubleValue() : 0.0;
    fl.schedDebCred = schedDebCredin != null ? schedDebCredin.doubleValue() : 0.0;
    fl.drugCred = drugCredin != null ? drugCredin.doubleValue() : 0.0;
    fl.ppdiscount = ppdiscountin != null ? ppdiscountin.doubleValue() : 0.0;
    fl.waiversubrogation = waiversubrogationin != null ? waiversubrogationin.doubleValue() : 0.0;
    fl.expenseconstant = expenseconstantin != null ? expenseconstantin.doubleValue() : 0.0;
    fl.tria = triain != null ? triain.doubleValue() : 0.0;
    fl.dtec = dtecin != null ? dtecin.doubleValue() : 0.0;
    fl.ccp = ccpin != null ? ccpin.doubleValue() : 0.0;
    if(fl == null)
         System.out.println("fl object is null BUDDY!");
    else
         System.out.println("fl.ppdiscount == "+fl.ppdiscount);
         System.out.println("fl.expenseconstant == "+fl.expenseconstant);
         System.out.println("fl.ccp == "+fl.ccp);
         myfactors.add(fl); <<<<<nullpointerexception here>>>>>>
    servlet code:
    ================================
    CellieRator rator = new CellieRator();
    long factordiv = bipoldiv.getDivision().getId();
    Double expenseconstant = new Double(0.0);
    Double safetyCredit = bipoldiv.getSafetyCredit();
    if(safetyCredit == null)
    throw new Exception("safetyCredit IS NULL.");
    Double ccpAp = bipoldiv.getCcpAp();
    if(ccpAp == null)
         throw new Exception("ccpAp IS NULL.");
    Double incLimit = bipoldiv.getLiabilityFactor();
    if(incLimit == null)
         throw new Exception("incLimit IS NULL.");
    Double deductibleCredit = bipoldiv.getDeductFactor();
    if(deductibleCredit == null)
         throw new Exception("deductibleCredit IS NULL.");
    Double schedDebCred = bipoldiv.getScheduledDebitCreditFactor();
    if(schedDebCred == null)
         throw new Exception("schedDebCred IS NULL.");
    Double ppdiscount = bipoldiv.getPromptPaymentDiscount();
    if(ppdiscount == null)
         throw new Exception("ppdiscount IS NULL.");
    Double drugCred = bipoldiv.getDrugFree();
    if(drugCred == null)
         throw new Exception("drugCred IS NULL.");
    Double waiversubrogation = bipoldiv.getWaiverSubro();
    if(waiversubrogation == null)
         throw new Exception("waiversubrogation IS NULL.");
    Double tria = bipoldiv.getLcm();
    if(tria == null)
         throw new Exception("tria IS NULL.");
    Double dtec = bipoldiv.getLcm();
    if(dtec == null)
         throw new Exception("dtec IS NULL.");
    System.out.print(factordiv+" "+safetyCredit+" "+ccpAp+" "+incLimit+" "+deductibleCredit+" "+schedDebCred+" "+drugCred+" "+ppdiscount+" "+waiversubrogation+" "+expenseconstant+" "+tria+" "+dtec);
    rator.addMyFactors(factordiv, safetyCredit, ccpAp, incLimit, deductibleCredit, schedDebCred, drugCred, ppdiscount, waiversubrogation, expenseconstant, tria, dtec);<<<<<<<<<and nullpointerexception here>>>>>>>>>>>>>>>>>>>>>

    dude... fresh eyes always work... thanks... I thought i had already done that... but thanks again for the heads up

  • Need help Sorting an Arraylist of type Object by Name

    Hey guys this is my first time posting on this forum so hopefully i do it the right way. My problem is that i am having difficulties sorting an Array list of my type object that i created. My class has fields for Name, ID, Hrs and Hrs worked. I need to sort this Array list in descending order according to name. Name is the last name only. I have used a bubble sort like this:
    public static void BubbleSort(TStudent[] x){
    TStudent temp = new TStudent();
            boolean doMore = true;
            while (doMore) {
                doMore = false;
                for (int i=0; i < x.length-1; i++) {
                   if (x.stuGetGPA() < x[i+1].stuGetGPA()) {
    // exchange elements
    temp = x[i]; x[i] = x[i+1];
    x[i+1] = temp;
    doMore = true;
    before many time to sort an array of my class TStudent according to GPA.  This time though i tried using an Array list instead of just a simple array and i can't figure out how i would modify that to perform the same task.  Then i googled it and read about the Collections.sort function.  The only problem there is that i know i have to make my own comparator but i can't figure out how to do that either.  All of the examples of writing a comparator i could find were just using either String's or just simple Arrays of strings.  I couldn't find a good example of using an Array list of an Object.
    Anyways sorry for the long explanation and any help anyone could give me would be greatly appreciated.  Thanks guys
    Edited by: Brian13 on Oct 19, 2007 10:38 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    ok still having problems I have this line of code to try and all Arrays.sort
    Arrays.sort(Employee, TEmployee.FirstNameComparator);Then in my class TEmployee i have
    public static Comparator FirstNameComparator = new Comparator() {
        public int compare(Object employee, Object anotherEmployee) {
          String lastName1 = ((TEmployee) employee).getEmpName().toUpperCase();
          String lastName2 = ((TEmployee) anotherEmployee).getEmpName().toUpperCase();     
           return lastName1.compareTo(lastName2);
      };Here is the rundown of what i have for this. I have 2 classes. One is called TEmployee and that class holds fields for Name, ID, Hrs Worked, Hourly Rate. Then i have another class called myCompany that holds an ArrayList of type TEmployee. Then i have my main program in a Jframe.
    So maybe i am putting them in the wrong spots. The code in TEmployee thats make the comparator is fine. However when i try to call Arrays.sort from class myCompany i get this
    cannot find symbol
    symbol: method sort (java.util.Array list<TEmployee>.java.util.Comparator
    location: class java.util.Arrays
    I have to put the comparator in TEmployee right because thats where my fields for Name are? Do i call the arrays.sort from my main program or do i call that from the class myCompany where my ArrayList of TEmployees are stored?
    Again guys thanks for any help you could give me and if you need any code to see what else is going on just let me know.

  • Need help to add the words in a text file to an arraylist

    I am new to java and I really need some help for my project.I want to add the words of a text file to an arraylist. The text file consist of words and the following set of punctuation marks {, . ; : } and spaces.
    thanks in advance :-)

    I/O: [http://java.sun.com/docs/books/tutorial/essential/io/index.html]
    lists and other collections: [http://java.sun.com/docs/books/tutorial/collections/index.html]

  • How do you incorporate an ArrayList inside a ComboBox (GUI Project Help)?

    Basically, I created a project around NBA Greats of Our Past. There is around 76 players so rather than typing all of them up in JCreator, how can you use an Arraylist to make things easier. I already created the spreadsheet on Excel with all the names. But the problem is that I don't know how to use them inside my ComboBox.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ComboBoxDemo extends JFrame {
         private String[] nbaGreats = {"Michael Jordan"};
         private ImageIcon[] nbaImage = {
              new ImageIcon("H:/jordan.jpeg")
         private String[] nbaDescription = new String[1];
         private DescriptionPanel descriptionPanel = new DescriptionPanel();
         private JComboBox jcbo = new JComboBox(nbaGreats);
         public static void main(String[] args)
              ComboBoxDemo frame = new ComboBoxDemo();
              frame.pack();
              frame.setTitle("NBA Greats");
              frame.setLocationRelativeTo(null);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
         public ComboBoxDemo() {
              nbaDescription[0] = "(Included Yet, Description not Included Yet";
              setDisplay(0);
              add(jcbo, BorderLayout.NORTH);
              add(descriptionPanel, BorderLayout.CENTER);
              jcbo.addItemListener(new ItemListener() {
                   public void itemStateChanged(ItemEvent e) {
                        setDisplay(jcbo.getSelectedIndex());
         public void setDisplay(int index) {
              descriptionPanel.setTitle(nbaGreats[index]);
              descriptionPanel.setImageIcon(nbaImage[index]);
              descriptionPanel.setDescription(nbaDescription[index]);
                   I Included a picture for reference. [http://img442.imageshack.us/i/98328443.png/]
    Edited by: lilazndood1 on May 28, 2010 6:50 AM

    Its a working example. The tutorial examplains the code in steps.
    Any code we give you will be no different.
    but it doesn't really help me because I don't understand itIf you have a specific question about the code from the demo then maybe we can help you, but "I don't understand it" is not a question.

  • Error while copying all rows into an ArrayList...plzzz help

    Hi all,
    Iam doing a small POC on publishing a Application module as webservices...iam stuck while copying the results of whereclause into an arraylist.. some one please help....below is the code
    public class matrixVOImpl extends ViewObjectImpl {
        /**This is the default constructor (do not remove)
        ArrayList al=new ArrayList();
        public matrixVOImpl() {
    public  ArrayList getCompLevels(String role){
        int x=0;
        int pos=0;
        setWhereClause("matrixEO.ROLE='"+role+"'");
        executeQuery();
        if (!hasNext())
                throw new JboException("unable to find role " +role);
        long i=getEstimatedRowCount();
        for(x=0;x<=i-1;x++){
        Row rw=getRowAtRangeIndex(x);************ //here lies the problem for me********************
    String comp= rw.getAttribute("Competency").toString();
        String lr=rw.getAttribute("LevelRequired").toString();
       al.add(0,comp);
      pos=pos+1;
       al.add(1,lr);
      pos=pos+1;
        return al;
    problem is at  Row rw=getRowAtRangeIndex(x); for loop is not workin here...when i manually put zero,first(),last() in place of x works fine i get the first row ..but if i put 1,2...10 or any number i get a null pointer exception..
    how to get all the rows ...wch can b copied to an arraylist...can someone help pllzz.Edited by: Oraclerr on Apr 10, 2009 12:31 PM

    I think it's because getRowAtRangeIndex depends of what the getRangeSize() value is on the view object before executeQuery is invoked. You can change this value in the properties of the viewobject or programmatically, using setRangeSize. If your range size is one, getRowAtRangeIndex(1) returns null, because the index i zero-based. You should only use range size if you only need to present ex. 10 rows a a time?

  • Help needed in  converting ArrayList to ArrayCollection

    I am converting an ArrayList (Java) to ArrayCollection of Flex .
    Please help me in this , i dont know whether this is correct approach or not
    I have a Created a User VO ActionScript class  on flex with two properties as uname , pass .
    [Bindable]       
            var result:ArrayCollection
    private function displayDetails(event:ResultEvent):void
    result = event.result as ArrayCollection;
    <mx:DataGrid  dataProvider="{result}">
                    <mx:columns>
                        <mx:DataGridColumn headerText="UserName" dataField="uname"/>
                        <mx:DataGridColumn headerText="Password" dataField="pass"/>
                    </mx:columns>
                </mx:DataGrid>
    This is from my Java DAO File :
                ResultSet rs = stmt.executeQuery("select NAME , PASS from Users");
                list = new ArrayList();
                while (rs.next()) {
                    User user = new User();
                    user.setUname(rs.getString(1));
                    user.setPass(rs.getString(2));
                    list.add(user);
            return list;
    With the below code ,the displayed DataGrid is empty with no data , please help me where i am doung wrong
    Do i need to do anything more ?? The data is coming well on to the lcds server console .
    Please help .

    Hi Kiran,
    Debugging solves most of the problems that you encounter ......you need to use a lot of debuggung so that you will come to know exactly what's
    happening indeed...
    So just put a break point at your displayDetails(event:ResultEvent):void  function and try to watch the event variable and check the event.result
    What is the datatype of the event.result ...Are you getting any data or is it null..???
    Please make these observations and let me know...
    Thanks,
    Bhasker

  • Help.  Does use of .txt file make sense or code directly into an ArrayList

    I am writing my first program and I want to put a series of information in various .txt files. This is because I will have a lot of different objects that I will create that will needed to be iterated over (most of the objects are similar in many ways). It seemed to me that a .txt file would be better than writing the items directly in an arraylist (if you know what i mean). What do you think?
    There will be 7 different objects that will be iterated over (and there will be 12 other objects doing other things as well, they will not be in .txt format), and I thought instead of having to maintain it through the actual code, I would just have .txt files that I create in notepad or something so that when I need to make changes to one of the 7 objects I only have to get the .txt file instead of having to wade through the code to find that object.
    Does this make sense?
    It seems that I will now have to do a lot of I / O to make it work, so now I am thinking maybe it is better to simply use the arrylist. Is there a benefit of one over the other in this circumstance?
    Also one of the objects has jpeg files that will need to be iterated over. Actually for these I will put them in an array list, because I can't seem to figure out yet how to get an image and the information about the image to display within I/O (like CD covers and their titles).
    Thank you for any help and suggestions I feel a little overwhelmed, but hopeful, with you kind folks.
    Peace
    NB I know that I am not using the correct terminology, but I hope that you can understand what I mean.
    Message was edited by:
    peacerosetx

    I am writing my first program and I want to put a
    series of information in various .txt files. Thisis
    because I will have a lot of different objects thatI
    will create that will needed to be iterated over
    (most of the objects are similar in many ways). It
    seemed to me that a .txt file would be better than
    writing the items directly in an arraylist (if you
    know what i mean). What do you think? I think I do not know what you mean. I also think
    that ArrayLists and files shouldn't replace eachI am going to use an ArrayList. Merci
    other.
    There will be 7 different objects that will be
    iterated over (and there will be 12 other objects
    doing other things as well, they will not be in.txt
    format),Seven objects? Twelve objects? Huh? Why not use
    arrays? And how do you get an object into a text
    file?
    and I thought instead of having to maintain
    it through the actual code, I would just have .txt
    files that I create in notepad or something sothat
    when I need to make changes to one of the 7 objectsI
    only have to get the .txt file instead of havingto
    wade through the code to find that object.
    Does this make sense? Your description? Not to me.
    It seems that I will now have to do a lot of I / Oto
    make it work, so now I am thinking maybe it isbetter
    to simply use the arrylist. Is there a benefit of
    one over the other in this circumstance? Uh, ArrayList is way faster and much easier
    modifyable.
    Also one of the objects has jpeg files that willneed
    to be iterated over. Actually for these I will put
    them in an array list, because I can't seem tofigure
    out yet how to get an image and the informationabout
    the image to display within I/O (like CD coversand
    their titles). "Display within I/O"? This makes no sense.
    NB I know that I am not using the correct
    terminology, but I hope that you can understandwhat
    I mean.If you're not using the correct terminology, there's
    no chance for us to understand you. If you say
    "objects" but mean "classes", then say classes.

  • Help with ArrayLists!

    Hi, I'm taking a java class at school, and I'm really, really bad at it. Anyway, I need help... I'm not even really sure what my problem is.. but I will try to explain.
    Anyway, I know I have a ton of problems, and I'm not even close to finishing the program, but here goes. I think part of my problem stems from making the arraylists into fish objects.. is there any way to work around that?
    The error that is popping up right now is "cannot resolve method- get (int)"; I'm thinking it doesn't work becuase I made the lists into fish objects, yes?
    Driver class
    * Driver class for the Fish class.
    * Christina
    * May 12, 2005
    import java.util.*;
    import cs1.Keyboard;
    public class Play
    public static void main (String [] args)
    boolean done = false;
    Fish comp = new Fish();
    Fish user = new Fish();
    Fish deck = new Fish();
    Fish userPairs = new Fish();
    Fish compPairs = new Fish();
    deck.fill();
    comp.deal();
    user.deal();
    System.out.println("Welcome to the lame, boring, Go Fish game... Yeah. Indeed.");
    System.out.println("Well.. you should know how to play.. if you don't I'd like to accuse you of" +
    " being an android, because only robots would not have played Go Fish before. Robots and hermits." +
    " Maybe you're a robot hermit? Or an alien? ");
    System.out.println("Your cards and pairs will be printed out before your turn. ");
    user.printCard();
    Method class:
    * Contains all the methods for the lame, command line version of Go Fish
    * Christina
    * May ??, 2005
    import java.util.*;
    import cs1.Keyboard;
    public class Fish
    ArrayList array = new ArrayList();
    Random generator = new Random();
    public Fish ()
    ArrayList array = new ArrayList();
    //ArrayList comp = new ArrayList();
    public void fill() //Fills the deck with 52 cards.
    for (int count= 0; count < 14; count++)
    for (int index = 0; index < 4; index++)
    Integer cardNum = new Integer(count);
    array.add(cardNum);
    public void deal(Fish array2) //Deals cards to the user and computer
    int num;
    for (int index=0; index <= 7; index++)
    num = generator.nextInt(52);
    array.add(array2.get(num));
    array2.remove(num);
    public void drawCard (Fish Array2)
    int num, length;
    length = deck.size();
    num = generator.nextInt(length);
    Integer card = new Integer(num);
    array.add(card);
    array2.remove(card);
    public void removeCard(int num)
    array.remove(num);
    public void printCard()
    for(int i = 0; i< array.size(); i++)
    System.out.println(array.get(i));
    /**public void sort()
    for(int i= 0; i < array.size(); i++)
    if(array.get(i).compareTo(i+1))
    array.add(i+1, array.get(i));
    //public int getCard()
    // int num;
    // return num.get();
    public void askUser(String card)
    System.out.println("Pick a card to ask for. Enter the number of the card ie 2." +
    "Note: Aces are represented by 0, Jacks by 11, Queens 12, and Kings 13.");
    card = Keyboard.readString();
    public void askComputer(int num, int length)
    length = this.size();
    num = generator.nextInt(length);
    this.get(num);
    System.out.println("Do you have any " + num);
    public void Pair(int pair)
    }

    Thanks a ton for the help^^ Unfortunately, because of my poor design no doubt, I still have plenty of problems.
    Oh, and I'd rather not
    Now, I have no idea why it refuses to acknowledge any of the method calls in the driver class.
    What the compiler says is wrong:
    --------------------Configuration: Final Project - j2sdk1.4.2_06 <Default> - <Default>--------------------
    C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\Final Project\Play.java:22: cannot resolve symbol
    symbol : method fill ()
    location: class java.util.ArrayList
    deck.fill();
    ^
    C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\Final Project\Play.java:23: cannot resolve symbol
    symbol : method deal ()
    location: class java.util.ArrayList
    comp.deal();
    ^
    C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\Final Project\Play.java:24: cannot resolve symbol
    symbol : method deal ()
    location: class java.util.ArrayList
    user.deal();
    ^
    C:\Program Files\Xinox Software\JCreatorV3LE\MyProjects\Final Project\Play.java:31: cannot resolve symbol
    symbol : method printCard ()
    location: class java.util.ArrayList
    user.printCard();
    ^
    4 errors
    Process completed.
    Now edited code:
    * Contains all the methods for the lame, command line version of Go Fish
    * Christina
    * May ??, 2005
    import java.util.*;
    import cs1.Keyboard;
    public class Fish
        ArrayList array = new ArrayList();
        Random generator = new Random();
        public Fish ()
        public void fill() //Fills the deck with 52 cards.
            for (int count= 0; count < 14; count++)
                for (int index = 0;  index < 4; index++)
                   Integer cardNum = new Integer(count);
                   array.add(cardNum);
        public void deal(ArrayList array2) //Deals cards to the user and computer
            int num;
            for (int index=0; index <= 7; index++)
            num = generator.nextInt(52); 
            array.add(array2.get(num));
            array2.remove(num);
        public void drawCard (ArrayList array2)
            int num, length;
            length = array2.size();
            num = generator.nextInt(length);
            Integer card = new Integer(num);
            array.add(card);
            array2.remove(card);
        public void removeCard(int num)
            array.remove(num);
        public void printCard()
            for(int i = 0; i< array.size(); i++)
                System.out.println(array.get(i));
        //public int getCard()
        //    int num;
        //    return num.get();
        public void askUser(String card)
            System.out.println("Pick a card to ask for. Enter the number of the card ie 2." +
             "Note: Aces are represented by 0, Jacks by 11, Queens 12, and Kings 13.");
            card = Keyboard.readString();
        public void askComputer(int num, int length)
            length = array.size();
            num = generator.nextInt(length);
            array.get(num);
            System.out.println("Do you have any " + num);
        public void Pair(int pair)
    * Driver class for the Fish class.
    * Christina
    * May 12, 2005
    import java.util.*; 
    import cs1.Keyboard;
    public class Play
        public static void main (String [] args)
            boolean done = false;
            ArrayList comp = new ArrayList();
            ArrayList user = new ArrayList();
            ArrayList deck = new ArrayList(52);
            ArrayList userPairs = new ArrayList();
            ArrayList compPairs = new ArrayList();
            deck.fill();
            comp.deal();
            user.deal();       
            System.out.println("Welcome to the lame, boring, Go Fish game... Yeah. Indeed.");
            System.out.println("Well.. you should know how to play.. if you don't I'd like to accuse you of" +
                        " being an android, because only robots would not have played Go Fish before. Robots and hermits." +
                        " Maybe you're a robot hermit? Or an alien? ");
            System.out.println("Your cards and pairs will be printed out before your turn. ");
            user.printCard();
    }

Maybe you are looking for

  • Advanced Property Editor

    As is the case with previously posted users, I find the persistent appearance of the Editor an annoying nuisance. Why has it not been addressed to the satisfaction of 'us' complaining users Can this function be disabled without impairing the use of t

  • Tables and subforms. How to combine to create a detail list ?

    Hi to all, i need to solve this issue. I've done many tries but nothing works. I have three tables : <tab1>, <tab2>, <tab3>. In context i tied its by where clausole so i have three nested tables. The third contains the texts for  a given position. Wh

  • Cannot get tones to work, tried EVERYTHING

    Hello everyone, I normally refrain from asking questions on a forum or ''community'', but seeing as I've tried every possible thing, I consider this to be a last resort. I'll keep it straight to the point, and easy to read. General information - I wa

  • Field Order not following Tab list

    I used Adobe LiveCycle Designer to convert a word document to a pdf with fields to insert data. I used the Tab order tool to choose the order of the fields. Everything is ordered the way I want it from 1 to 53. It looks great till I actually start cl

  • Crazy data usage suddenly on Mifi! 10gb in one day?

    I noticed earlier this month that I got a notification for my data usage only about 10 days into my plan and thought it was unusual, but as my son had been streaming a music video I increased my plan, downloaded said video and disconnected his comput