开发者

FIleNotFoundException - illegal start of expression - NetBeans

开发者 https://www.devze.com 2023-04-11 09:56 出处:网络
I get the following error message \'llegal start of expression\' at line throws FileNotFoundException

I get the following error message 'llegal start of expression' at line

throws FileNotFoundException

I have done some research but wasn't able to fix it. Can you help? Many thanks, zan

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());
                }
            }
        }
    }


You shouldn't have a curly brace before the throws keyword :

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

Note that a class should always start with an uppercase letter.


Improper use of throws.

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

It is better to use try..catch

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


Your syntax is wrong. Check your source and/or the language specification.

0

精彩评论

暂无评论...
验证码 换一张
取 消