Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

java.util.NoSuchElementException error help

$
0
0
This is my code
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;


public class addDog
{

private ArrayList<Dog> dogsList;

//Constructors
public addDog()
{
    dogsList = new ArrayList<Dog>();

}

//Getter and Setter Methods
//Operational Methods

public void loadDogs()
{
    try
    {
      File file = new File("res/dogs.txt");
      Scanner s = new Scanner(file);

      while(s.hasNext())
      {

         String line = s.nextLine();
         StringTokenizer st = new StringTokenizer(line, ";");
         String name = st.nextToken();
         double time = Double.parseDouble(st.nextToken());
         int penalty = Integer.parseInt(st.nextToken());
         String course = st.nextToken();

         Dog dogobject = new Dog(name, time, penalty, course);

         dogsList.add(dogobject);


    }

    s.close();
    }
    catch(FileNotFoundException fnfe)
    {
        fnfe.printStackTrace();
    }

    for(Dog g : dogsList)
        System.out.println(g);


}


public static void main(String args[])
{
    addDog h = new addDog();

    h.loadDogs();


}

}



Sorry i forgot to add my question haha.

So i was wondering if you guys could help me figure out why my code wont compile and why i am getting this error

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>