Member Avatar for qew.brown

Hi,

This is my first post, forgive me for not being immediately familiar with any forum protocols.

I am trying to read in a txt file and store the data in my class. I keep running into this error

Exception in thread "main" java.lang.NumberFormatException: For input string: "./src.Chance"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:481)
at java.lang.Integer.parseInt(Integer.java:527)
at Driver.main(Driver.java:31)

this is my code

import java.util.*;

public class Driver {


    private static Scanner stringScan;
    private static Scanner cardScan;

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        //Instantiations
        Card Chance[] = new Card[16];

        cardScan = new Scanner("./src.Chance");
        while (cardScan.hasNext()) {
            stringScan = new Scanner(cardScan.next());
            stringScan.useDelimiter(",");
            Integer.parseInt(stringScan.next().trim());
            System.out.println(Chance.toString());

        }//End Chance
    }//End main
}//End Class

This is my Card class constructor

public Card(String cardName, int value, int cardEffect ) {
        // TODO Auto-generated constructor stub

        this.cardEffect = cardEffect;
        this.value = value;
        this.cardName = cardName;

    }// End Card

and part of the txt file I'm trying to read in.

Take a ride on the Reading Railroad If you pass go collect $200,200,6
Bank pays you divedend of $50,50,0
Advance to Illinois Avenue,0,25
Your building and loan matures Collect $150,150,0

I know this is something simple and I'm just missing one line of code but I cannot seem to find it and my old workspace isn't available for reference. Please help.

You probably want to read the contents of the file, not just parse the file name. So I think you need something like this:

cardScan = new Scanner(new File("./src.Chance"));

and I would just add throws Exception to the main method.

Member Avatar for qew.brown

Thanks, that seemed to fix that problem. I knew it was something simple. I appreciate it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.