Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: It doesn't detect my file

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default It doesn't detect my file

    I'm making a file that fills a grid of characters, but it doesn't detect the file.

        String map;
        String texture;
        Scanner asdf;
        int rows;
        int cols;
        char Map[][];
        public Map()
        {
     
        }
     
        public Map(String map)
        {
            System.out.println("Finding map....");
            loadGrid(map);
            System.out.println("Map Loaded");
            if (texture == "" || texture == null) {
                System.out.println("Texture not found...");
     
            }
            else System.out.println("Texture Loaded.");
     
        }
     
     
        //loads the grid
        public void loadGrid(String map)
        {
     
                asdf = new Scanner(map);
     
            rows = asdf.nextInt();
            cols = asdf.nextInt();
            Map = new char[rows][cols];
            for (int i = 0; i < rows; i++) {
                String a = asdf.nextLine();
                for (int j = 0; j < cols; j++) {
                    Map[i][j]=a.charAt(j);
                }
            }
     
        }
     
        //prints the characters making up the map
     
     
            public void print()
        {
            for (int i = 0; i < Map.length; i++) {
                for (int j = 0; j < Map[i].length; j++) {
                    System.out.print(Map[i][j] + " ");
                }
                System.out.println("");
            }
        }

    And it keeps giving me this error:


    run:
    Map initialized
    Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Scanner.java:909)
    at java.util.Scanner.next(Scanner.java:1530)
    at java.util.Scanner.nextInt(Scanner.java:2160)
    at java.util.Scanner.nextInt(Scanner.java:2119)
    at xavi.Map.loadGrid(Map.java:49)
    at xavi.Xavi.main(Xavi.java:17)
    Java Result: 1
    If anyone knows what my problem is I'd greatly appreciate the help... :/


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: It doesn't detect my file

    InputMismatchException: The file is being found and read, but that data in the file does not match the type expected by Scanner. Add some print statements to see what is being read from the file to see why there is a data type mismatch.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks I'll do that and get back to you

Similar Threads

  1. JEditorPane doesn't load html file when jar executable run
    By dancaer69 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 12th, 2013, 10:46 AM
  2. ZIP file created in JAVA doesn't work as it is
    By QooBooS in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: July 30th, 2012, 12:35 PM
  3. File Reading code doesn't work
    By koryvandell in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2011, 08:40 AM
  4. Issue with code. Does not detect duplicate names in file
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 29th, 2011, 01:13 AM
  5. How can I detect the end of a line in a file ?
    By lumpy in forum Java Theory & Questions
    Replies: 3
    Last Post: February 18th, 2010, 03:13 AM

Tags for this Thread