Hi, I'm working on this GUI program and I needed to call a method from another class which throws an exception. I tried doing this:
Scanner s;
s=UsingFiles.setFileScanner("board1") throws FileNotFoundException;
But it says I need a semicolon after ("board1"). I did that and it said that "throws FileNotFoundException;" is not a valid expression.
Please help!!!!
Well, I can see you are using Java. I don't know Java. But, from researching the problem, the "throws exception" clause is used when declaring a function. Your code is clearly not declaring a function, it is calling a function and therefore "throws FileNotFoundException" is not valid in this context. The compiler expects an end of line after s=UsingFiles.setFileScanner("board1") thus the reason why it insists you put a semi-colon there and complains about anything extra like "throws FileNotFoundException." I derived that from my 5 minute crash course in Java - so I might be wrong.
✨ Ask AI
AI can make mistakes. Check the cited posts. Archived advice can be out-of-date
Don't include personal information. Questions and selected public posts go to OpenAI. About Ask AI