簡體   English   中英

在開關2的情況下,我遇到了一個問題,該問題給了我NoSuchElementException?

[英]I've got a problem in case 2 of the switch that gives me the NoSuchElementException?

我有以下代碼可以在學校的Windows計算機上正常工作,但是在我的MacOS上卻無法使用。 情況2應該給出一個學生的班級編號,但是它僅在我的MacOS中才給我NoSuchElementException 為什么它在我的MacOS上不起作用?

case 2:
            System.out.println("Inserisci il cognome dello studente");
            String surname = scan.next();
            System.out.println("");
            System.out.println("Inserisci il nome dello studente");
            String name = scan.next();
            System.out.println("");

            File directory = new File("files" + File.separator + "class");;
            int fileCount = directory.list().length;
            for(int i=0; i< fileCount; i++ ){
                cn = ClassNumber.values()[enumNumb];
                if(enumNumb<3){
                    for(int j = 1; j<6; j++){
                        File serchStudents = new File("files" + File.separator + "class//" + j + cn + ".txt");
                        Scanner scS = new Scanner(serchStudents);
                        while(scS.hasNextLine()){
                            if(surname.equals(scS.next())/*&& name.equals(sc.next())*/){
                                System.out.print(j);
                                System.out.println(cn);
                                enumNumb=0;
                            }
                        }
                    }
                    enumNumb++;
                }
                if(enumNumb>=3){
                    for(int j = 3; j<6; j++){
                        File serchStudents = new File("files" + File.separator + "class" + File.separator + j + cn + ".txt");
                        Scanner scS = new Scanner(serchStudents);
                        while(scS.hasNextLine()){
                            if(surname.equals(scS.next())/*&& name.equals(sc.next())*/){
                                System.out.println("Lo studente fa parte della classe : ");
                                System.out.print(j);
                                System.out.println(cn);
                                i=fileCount;
                                enumNumb=0;
                            }
                        }
                    }
                    enumNumb++;
                }
            }
            System.out.println("Vuoi fare altro ?");
            answer = scan.next();
            break;

我剛剛在netBeans上安裝了一些需要安裝的東西,它已經起作用了,所以我猜很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM