Results 1 to 11 of 11
Like Tree4Likes
  • 3 Post By DarrylBurke
  • 1 Post By Norm

Thread: Really basic error: cannot find symbol

  1. #1
    gjwcarsaig is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default Really basic error: cannot find symbol

    I've just started trying to use Java and am getting nowhere.

    I know the answer to this will be obvious, but as the compiler insists on returning the same error I will be stuck unless I can solve it.

    I thought this code would be simple enough to be foolproof, but obviously not in my case.

    Anyway, here's the code.

    Java Code:
    import java.io.*;
    
    public class FileRead 
    {
     public static void main(String args[])
      {
      
      FileInputStream fstream = new FileInputStream("sometext.txt");
      fstream.close();
      }
    }
    And the errors I get:

    Building "FileRead"
    C:\Users\user\j2mewtk\2.5.2\apps\FileRead\src\File Read.java:8: cannot find symbol
    symbol : class FileInputStream
    location: class FileRead
    FileInputStream fstream = new FileInputStream("sometext.txt");
    ^
    C:\Users\user\j2mewtk\2.5.2\apps\FileRead\src\File Read.java:8: cannot find symbol
    symbol : class FileInputStream
    location: class FileRead
    FileInputStream fstream = new FileInputStream("sometext.txt");
    ^
    2 errors
    com.sun.kvem.ktools.ExecutionException
    Build failed


    I thought FileInputStream was included in java.io.*, but still it refuses to work.

    Any help appreciated.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    You have a unhandled FileNotFound/IOException
    Java Code:
    		FileInputStream fstream;
    		try {
    			fstream = new FileInputStream("sometext.txt");
    			fstream.close();
    		} catch (IOException e) {
    			e.printStackTrace();
    		}

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    Are you posting the correct error for the code you have posted?
    I do not get that error when I compile it. I get the error mentioned in post#2

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,537
    Blog Entries
    7
    Rep Power
    20

    Default

    Can you find a file named rt.jar in your JRE directory?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default

    C:\Users\user\j2mewtk\2.5.2\apps\FileRead\src\File Read.java:8: cannot find symbol
    symbol : class FileInputStream
    :
    :
    com.sun.kvem.ktools.ExecutionException
    Java ME does not have a FIleInputStream class. Which you could have discovered for yourself by looking at the documentation.

    You can't use Java SE classes in Java ME.

    Next time round, please post Java ME issues in the relevant forum, either CLDC and MIDP or Sun Java Wireless Toolkit.

    db

    edit Java ME has no use for a public static void main(...) method either. Are you by any chance trying to use the wireless toolkit to develop a Java SE application? It doesn't work that way.
    Last edited by DarrylBurke; 07-30-2011 at 03:30 PM.
    Norm, Fubarable and JosAH like this.

  7. #7
    gjwcarsaig is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default

    Apologies for wasting your time due to my ignorance. It seems like Java in whatever form is going to be too difficult for me.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,457
    Rep Power
    25

    Default

    A lot of programming requires attention to detail. You shouldn't assume anything.
    Reading the API documentation for the classes you want to use is always a good idea.
    Fubarable likes this.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,250
    Rep Power
    19

    Default

    Quote Originally Posted by gjwcarsaig View Post
    Apologies for wasting your time due to my ignorance. It seems like Java in whatever form is going to be too difficult for me.
    Don't give up so easily! Apparently what you want to learn is Java SE. Start here: The Java™ Tutorials

    db

  10. #10
    amanrv is offline Member
    Join Date
    Jul 2011
    Posts
    12
    Rep Power
    0

    Default

    nothing's too difficult. if you find problems with fileinputstream, you can use filewriter.

    here's the code for you.

    Java Code:
    import java.io.*;
    class test
    {public static void main(String arg[])throws Exception
    {File file=new File("me.txt");
    FileReader in=new FileReader(file);
    in.close();
    }
    }

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,537
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by amanrv View Post
    nothing's too difficult. if you find problems with fileinputstream, you can use filewriter.

    here's the code for you.

    Java Code:
    import java.io.*;
    class test
    {public static void main(String arg[])throws Exception
    {File file=new File("me.txt");
    FileReader in=new FileReader(file);
    in.close();
    }
    }
    I don't see a FileWriter in your code anywhere; your entire reply is crap anyway; the correct answer was already given by Darryl in reply #6. Always first read the entire thread before you reply yourself. In your case: think again before you reply because your reply was utter nonsense.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Cannot find symbol error?
    By Josep_16 in forum New To Java
    Replies: 2
    Last Post: 06-19-2011, 07:14 PM
  2. Error: Cannot Find Symbol
    By mawright in forum New To Java
    Replies: 4
    Last Post: 04-14-2011, 02:41 PM
  3. Cannot find symbol Error
    By new_Java in forum New To Java
    Replies: 3
    Last Post: 02-17-2011, 11:23 PM
  4. error cannot find symbol
    By jcoon3 in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 10:56 PM
  5. Replies: 9
    Last Post: 10-18-2008, 08:26 PM

Posting Permissions

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