Error in creating InputStream object
I am trying to load a training model provided under OpenNlp using eclipse.
The code segment giving the error is:
Code:
InputStream modelIn = new FileInputStream("en-sent.bin");
Here, "en-sent.bin" is the name of the file in my root directory.
The error given is:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type FileNotFoundException
at opennlp.mySentence.main(mySentence.java:18)
I need to pass the object 'modelIn' as an arguement to the constructor of a class which will perform the training, and it needs the argument as an InputStream object only.
Hence I cannot use the 'modelIn' object of classes such as 'File' etc.
Any help on fixing this issue will be appreciated.
Re: Error in creating InputStream object
Creating a new FileInputStream can potentially generate an Exception, so you have to handle it appropriately. Recommended reading: Catching and Handling Exceptions (The Java™ Tutorials > Essential Classes > Exceptions)
Re: Error in creating InputStream object
Quote:
Originally Posted by
KevinWorkman
Creating a new FileInputStream can potentially generate an Exception, so you have to handle it appropriately.
Thanks a lot. This was indeed the problem here.
Adding a "throws FileNotFoundException" did the trick.
Problem solved :)
Re: Error in creating InputStream object
Quote:
Originally Posted by
er.raj
Thanks a lot. This was indeed the problem here.
Adding a "throws FileNotFoundException" did the trick.
Problem solved :)
You also might consider catching the Exception and displaying a meaningful error message.