Results 1 to 8 of 8
  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default Making an ArrayList

    I am also building my second program.
    With this one I am havind another text file, and every line I would like to have in an ArrayList. To run a search against another .txt file.

    I think my arrayList is build correctly but he does give me an error:

    Note: C:\Documents and Settings\......\SeqFinder.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    And the output is also wrong. I get in the terminal to see the usage and other things I have not asked for. :(

    Java Code:
     
    import java.util.*;
    import java.io.*;
    
    public class SeqFinder {
    	public static void main(String[] args) {
    
    		// We maken een String aan voor de ArrayList.
    		ArrayList arrayList = new ArrayList();
    
    		// Create an instance of File for file you want to load in the script.
    		File file1 = new File("TwoQuery.txt");
    
    		try {
    			// Create Scanner.
    			Scanner x = new Scanner(file1);
    			// We read the lines one by one in the file.
    			while (x.hasNextLine()) {
    				String line = x.nextLine();
    				// Print the read in file:
    				System.out.println(line);
    
    				arrayList.add(line);
    				System.out.println("List size: " + arrayList.size());
    
    			}
    
    		}	catch (FileNotFoundException e) {
    				e.printStackTrace();
    		}
    	}
    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default

    Your first problem is not an error, it is simply a warning that you aren't using generics. Generics tell the compiler what is allowed in the list. You don't have to use them, but you'll get that warning if you don't. You should be doing this instead:
    Java Code:
    ArrayList<String> arrayList = new ArrayList<String>();
    And I don't understand what your second problem is. What are you seeing that you didn't expect to see? Post the output.

    PS- This has nothing to do with applets.

  3. #3
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default error

    In the file I read to the arrayList I have:

    > code1
    > code2

    But what I get to see in the command line is not this.
    But:

    Usage: java [-options] class [args...]
    (to execute a class)
    or java [-options] -jar jarfile [args...]
    (to execute a jar file)

    where options include:
    -client to select the "client" VM
    -server to select the "server" VM
    -hotspot is a synonym for the "client" VM [deprecated]
    The default VM is client.

    ....................
    .........
    .........................

    -splash:<imagepath>
    show splash screen with specified image
    Press any key to continue . . .

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default

    I think you're doing something wrong. I don't think you're running the file at all. How exactly are you attempting to run this (start at step 1- how are you opening the command prompt)?

  5. #5
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default it worked?

    So it worked reading in all the lines in the .txt file to the arrayList?
    That is what I was testing actualy. :)

  6. #6
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,879
    Rep Power
    8

    Default

    Quote Originally Posted by Lund01 View Post
    So it worked reading in all the lines in the .txt file to the arrayList?
    That is what I was testing actualy. :)
    Huh? I have not commented on whether or not your algorithm will work- the only way to find out is for you to run it. I'm guessing that you have not yet successfully run the file. Tell us how you're trying to do that, and we can go from there.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    what I get to see in the command line
    Can you show the command you entered?
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  8. #8
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default

    I think I got it.
    Also made a small adjustment, and I think it works now.
    Will work this out further now.
    Thanks for the help with this one. :)

Similar Threads

  1. Creating an ArrayList from an ArrayList
    By Klahking in forum New To Java
    Replies: 17
    Last Post: 09-09-2010, 03:34 PM
  2. Need help making a GUI
    By DrKilljoy in forum New To Java
    Replies: 21
    Last Post: 07-15-2010, 03:44 AM
  3. Need help making .jar
    By yoodidoo in forum Eclipse
    Replies: 4
    Last Post: 08-03-2009, 08:57 PM
  4. Replies: 3
    Last Post: 07-15-2009, 06:10 AM
  5. Replies: 2
    Last Post: 04-21-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •