Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By KevinWorkman

Thread: Error in creating InputStream object

  1. #1
    er.raj is offline Member
    Join Date
    Mar 2012
    Posts
    15
    Rep Power
    0

    Default 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:

    Java 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.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default 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)
    er.raj likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    er.raj is offline Member
    Join Date
    Mar 2012
    Posts
    15
    Rep Power
    0

    Default Re: Error in creating InputStream object

    Quote Originally Posted by KevinWorkman View Post
    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 :)

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,691
    Rep Power
    8

    Default Re: Error in creating InputStream object

    Quote Originally Posted by er.raj View Post
    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.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Replies: 3
    Last Post: 01-04-2012, 02:30 PM
  2. Replies: 9
    Last Post: 07-29-2011, 02:18 PM
  3. Creating an InputStream
    By c26354 in forum New To Java
    Replies: 10
    Last Post: 07-12-2011, 04:48 AM
  4. Defining the inputStream object
    By yahyaaa in forum New To Java
    Replies: 11
    Last Post: 06-17-2010, 04:10 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 03:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •