Results 1 to 7 of 7
  1. #1
    artemff is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default Why this code don't work?

    Why this code don't work:

    .......
    import javax.microedition.io.*;
    ......
    ......
    String filename;
    BufferedReader in = new BufferedReader(new FileReader(filename));
    .....

    In NetBeans IDE 5.0.
    Error: cannot find symbol...

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

  3. #3
    artemff is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Fubarable, how set up NetBeans IDE to recognize it?
    Last edited by artemff; 12-24-2009 at 10:11 PM.

  4. #4
    Pixio is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    Java Code:
    String filename;
    BufferedReader in = new BufferedReader(new FileReader(filename));
    If there is no code between these lines, it's error maybe because u haven't initialized filename yet? String filename points to null.

  5. #5
    cselic is offline Senior Member
    Join Date
    Apr 2010
    Location
    Belgrade, Serbia
    Posts
    278
    Rep Power
    5

    Default

    first initialize filename.
    second write code for file not found exception.

    code will look something like that:

    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;

    .....

    String filename= "input.txt";
    try {
    BufferedReader in = new BufferedReader(new FileReader(filename));
    } catch(FileNotFoundException exception) {
    exception.printStackTrace();
    }

    for practice I wrote a little class:
    Java Code:
    import java.io.BufferedReader;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    
    public class BaferedExample {
    	public BaferedExample() {
    		
    	String filename= "input.txt";
    	try {
    	BufferedReader in = new BufferedReader(new FileReader(filename));
    	} catch(FileNotFoundException exception) { 
    		exception.printStackTrace(); 
    		}
    	}
    }

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by artemff View Post
    Fubarable, how set up NetBeans IDE to recognize it?
    That package is a non-standard package. So you've to import it into your project. Actually added in class path. Did you do that?

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Pixio View Post
    Java Code:
    String filename;
    BufferedReader in = new BufferedReader(new FileReader(filename));
    If there is no code between these lines, it's error maybe because u haven't initialized filename yet? String filename points to null.
    Actually that's lead to NullPointerException, not to cannot find symbol .....

    It could rise due to two reason. Variable use without declaring, and use of additional package resources (actually this is same as use of variables without declaring in depth)

Similar Threads

  1. How does the '*' work in the code?
    By DrMath in forum New To Java
    Replies: 3
    Last Post: 10-28-2009, 09:26 AM
  2. Replies: 2
    Last Post: 07-29-2009, 12:23 PM
  3. Replies: 6
    Last Post: 02-06-2009, 08:05 PM
  4. how does this code work...explain me the execution please...
    By vital parsley in forum New To Java
    Replies: 3
    Last Post: 07-25-2008, 04:50 AM
  5. the code dosent work
    By pcman in forum Java 2D
    Replies: 1
    Last Post: 03-20-2008, 08:20 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
  •