This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark ""FileNotFoundException", but it Watch ""FileNotFoundException", but it New topic

"FileNotFoundException", but it's there...

Kari Nordmann
Ranch Hand

Joined: Feb 12, 2007
Posts: 38
I have a task in which I put pieces of a sudokuprogram together.
Right now I'm trying to get the program to read sudokus from files instead of creating them manually.
The problem is that when I try to run the method lesFraFil(readfromfile), I just keep gettings errors like FileNotFoundException, even before I run the program (using Eclipse). The file is there, it's right in the same folder where the .java's and .class' to the program are.
I get the feeling the error is actually casued by something completely different than the file not being found, so I don't really understand the error... Can anyone explain what is wrong?

Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
The first thing to do is to put the lineafter the lineto check exactly what file the program is trying to access.

Jhakda Velu
Ranch Hand

Joined: Feb 26, 2008
Posts: 167
The File may be present, but you lesFraFil method throws a filenotfoundexception. but you calling method doesn't handle it. It is failing at compile time only,not at run time
Since you are throwing the exception in your called method(lesFraFil ), the calling method should catch it and do somethg

If I become filthy rich, I'll sponsor research for painless dental treatment at Harvard Medical School. Thats why,I'm learning Java.I have 32 teeth, 22 are man made.
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
Well spotted Jhakda. I guess that's what the OP meant when he said 'I just keep gettings errors like FileNotFoundException, even before I run the program'
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3381

Yes, that is right. The eclipse IDE might have been asking you to 'deal' with it by handling the errors in the statement which calls the method throwing such exceptions!

Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Rob Spoor

Joined: Oct 27, 2005
Posts: 20193

Method SudokuBrett has to either catch or rethrow all exceptions thrown by the lesFraFil method.

Now the compiler will only complain about FileNotFoundException and IOException, because the other ones are unchecked exceptions. If you don't know what that means, the search on this forum, Google or Wikipedia can tell you all you need to know.

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: "FileNotFoundException", but it's there...
jQuery in Action, 3rd edition