Java StringTokenizer exception

My coding have no error but i don't understand why there is error when i run. Below are the complete exception:-

java.util.NoSuchElementException
Initializing population...
   at java.util.StringTokenizer.nextToken(Unknown Source)
   at Input.takeinput(Input.java:44)
   at schedule.main(schedule.java:33)
Exception in thread "main" java.lang.IllegalArgumentException: bound must be positive
   at java.util.Random.nextInt(Unknown Source)
   at schedule.createpopulation(schedule.java:244)
   at schedule.main(schedule.java:37)

Where does the exception really happen?

For the first error,here's the coding (Input.java:44)

File file = new File("input.txt");
        Scanner scanner = new Scanner(file);
        while(scanner.hasNextLine()){
            String line = scanner.nextLine();
            //StringTokenizer st = new StringTokenizer(line, ";");
            //input student and sv
            if(line.equals("student")){
                nostud = 0;
                while(!(line=scanner.nextLine()).equals("examiner")){
                    StudData[nostud] = new Student();
                    StringTokenizer st = new StringTokenizer(line, ";");
                    StudData[nostud].setName(st.nextToken());
                    StudData[nostud].setCode(st.nextToken());
                    StudData[nostud].setSvName(st.nextToken());
                    StudData[nostud].setSvCode(st.nextToken());
                    nostud++;
                }
            }

and (schedule.java:33)

input.takeinput();

For the second error.(schedule.java:44)

while(!flag){
    int ex = r.nextInt(noexm);

and (schedule.java:37)

createpopulation();

Answers


First Exception means that you are calling nextToken more than necessary. There is no "next token" on the string you are tokenizing. For example, for the string a;b;c, you can call nextToken only 3 times, the 4th call would throw an Exception like the one you had: NoSuchElementException Second Exception means that your noexm variable is a negative integer, which is not good. Try to debug and find out the value of noexm and figure out why it is negative.


Need Your Help

IBM MobileFirst Add envirnment via ant script

ant ibm-mobilefirst mobilefirst-cli

Is there a way to add environment (android,windows and IOS) using ant with the help of any jar Files.

How do I target a GridViewRow with an AJAX.Net Toolkit PopupExtender?

asp.net javascript gridview asp.net-ajax

I have a lot of data to display in a GridView. Because there's so much information per row, I'd like to be able to display additional information when a user clicks on the row, so I thought a