Results 1 to 5 of 5
  1. #1
    Zedd is offline Newbies
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default Exporting my first program problems

    So I use Eclipse, and I have this wonderful program that I'd like to export as a jar file. I do, and it doesn't work. Google magic leads me here, and I find out that I can't use the File class, I have to change it to a resource stream or something.

    I am just at the beginning of trying to change everything over from File reading to Resource streaming. In the main method of the class I start with, I try to read a text file and add to an ArrayList of strings (cards) like so:
    Java Code:
    		InputStream deckFile = ThisClass.class.getResourceAsStream("cards.txt");
    		InputStreamReader isr = new InputStreamReader(deckFile);
    		BufferedReader br = new BufferedReader(isr);
    
    		String line = "";
    		try {
    			line = br.readLine();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    		while(line != null) {
    			cards.add(new Card(line));
    			try {
    				line = br.readLine();
    			} catch (IOException e) {
    				e.printStackTrace();
    			}
    		}
    PROBLEM IS... the getResourceAsStream thing returns null (in eclipse... I think something else goes wrong when I try to execute the jar file).

    The program uses Swing, so it's not really a command line thing. I ran it on the command line, and got a ClassNotFoundException...

    halp

  2. #2
    Zedd is offline Newbies
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    This is the thread I referred to in my post:
    File not found when using jar

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    Where is cards.txt?
    Is it in a source folder?
    Also, you can use getResource to get the URL, and print that out to see exactly where it's looking for the file.

  4. #4
    Tedward is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    It could just be that your text file, "cards.txt" isn't in the right place. You could add this in there if you don't have it already.
    Java Code:
    throws FileNotFoundException
    You could try just running that section in a shorter code to see if you didn't code it properly.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    I ran it on the command line, and got a ClassNotFoundException...
    Sounds like you are having a problem building the jar file.
    I don't use your IDE so can't help you there. Research how to have the IDE put files in the jar.

Similar Threads

  1. problems with the program
    By stefandanielsen in forum AWT / Swing
    Replies: 5
    Last Post: 03-03-2011, 08:04 AM
  2. problems when i run the program
    By stefandanielsen in forum New To Java
    Replies: 3
    Last Post: 03-03-2011, 08:02 AM
  3. problems with the program
    By stefandanielsen in forum New To Java
    Replies: 1
    Last Post: 03-01-2011, 10:08 AM
  4. Problems with program..
    By spatel14 in forum New To Java
    Replies: 8
    Last Post: 07-01-2010, 02:51 PM
  5. Program using JPanel - problems
    By doozer8688 in forum New To Java
    Replies: 6
    Last Post: 11-04-2008, 11:16 PM

Posting Permissions

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