簡體   English   中英

FIleNotFoundException - 非法啟動表達式 - NetBeans

[英]FIleNotFoundException - illegal start of expression - NetBeans

我在行收到以下錯誤消息'llegal start of expression'

拋出FileNotFoundException

我做了一些研究,但無法修復它。 你能幫我嗎? 非常感謝,贊

import java.io.FileNotFoundException;
    import java.io.File;
    import java.util.Scanner;
    import static java.lang.System.out;

    public class training{
        public static void main(String[]args){

            throws FileNotFoundException{

            Scanner diskScanner = new Scanner(new File("occupancy"));

            out.println("Room\tGuests");

            for(int roomNum = 0; roomNum < 10; roomNum ++){
                out.print(roomNum);
                out.print("\t");
                out.println(diskScanner.nextInt());
                }
            }
        }
    }

你應該在throws關鍵字之前沒有大括號:

public static void main(String[]args) throws FileNotFoundException {
                                     ^-- no curly brace

請注意,類應始終以大寫字母開頭。

throws使用不當。

public static void main(String[]args) throws FileNotFoundException
{
 ..
}

最好使用try..catch

public static void main(String[]args) 
    {
      try
       {
        ..
       }catch(FileNotFoundException ex)
        {
          //
        }
    }

你的語法錯了。 檢查您的來源和/或語言規范。

暫無
暫無

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

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