Exception in thread "main" - java.util.InputMismatchException error? -


i getting error , don't know what's problem:

exception in thread "main" java.util.inputmismatchexception @ java.util.scanner.throwfor(unknown source) @ java.util.scanner.next(unknown source) @ java.util.scanner.nextint(unknown source) @ java.util.scanner.nextint(unknown source) @ productratings.loadfile(productratings.java:45) @ productratings.main(productratings.java:178) 

here's code:

enter image description here

in first photo error in line of 45 (customer.setcustomerid(scanner.nextint();)

and other part of code:

enter image description here

in second photo error in line of 178(ratingmgr.loadfile();)

public static void main(string[] args) {    string filename="ratings.txt";    productratings ratingmgr=new productratings(filename);    try {        ratingmgr.loadfile();         string typename[]={"all","national","international","national doctor"};        for(int i=0;i<typename.length;i++)        {            system.out.println("average rating of products "+typename[i]+" customers");            double avg[]=ratingmgr.getaveragerating(i);            for(int j=0;j<avg.length;j++)            {                system.out.println("product "+ratingmgr.getproductname(j)+": "+string.format("%.2f",avg[j]));            }        }         ratingmgr.printbelowaveragecustomers(0);        ratingmgr.printbelowaveragecustomers(1);     } catch (filenotfoundexception e) {        system.out.println("file not found : "+filename);    }   //now start reading customer data    while(scanner.hasnext())    {        int ratings[]=new int[numofproducts];        custtype=scanner.next();        if(custtype.equals("n")) //if customer type national            customer=new nationalcustomer();        else            customer=new internationalcustomer();         customer.setcustomerid(scanner.nextint()); //read customer data 1 one        customer.setname(scanner.next());        customer.setsurname(scanner.next());        //system.out.println(customer.getname());        if(custtype.equals("n"))        {            ((nationalcustomer)customer).setlicence(scanner.nextint());            ((nationalcustomer)customer).setoccupation(scanner.next());        }        else        {            ((internationalcustomer)customer).setcountry(scanner.next());            ((internationalcustomer)customer).setcity(scanner.next());        }         customers.add(customer); //add cusstomer list 

check file ratings.txt content. when check scanner.hasnext(), guarantees custtype=scanner.next(); read properly, success of next scanner.next() calls depends on file contents, obviously.

you should check, if ok file contents (eplecially @ last line). moreover, check every scanner.nextint() receives numeric vaue file: in case enter string or character instead, throw java.util.inputmismatchexception.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -