Results 1 to 4 of 4

Thread: Problem in BufferedReader

  1. #1
    Join Date
    Nov 2009
    Posts
    583

    Problem in BufferedReader

    Hi
    I am very new to java, yesterday I was just trying a program and when I executed the program in my PC it given me a message "cannot resolve symbol" What does this mean? Any I fix the problem easily? Can you guys help me. Thanks in advance. I have posted my code below.
    Code:
    public class BufferedReader
    {
        public static void main (String[]args)
        {
            BufferedReader dtln = new BufferedReader (new InputStreamReader(System.in));
           String no;      
            try
            {
                no = dtln.readLine();
                int nober1 = Integer.parseInt(no);
                no = dtln.readLine();
                int nober2 = integer.parseInt(no);
            }
            
            catch (IOException e)
            {
                System.out.println("Error!");
            }        
            
            int sum = nober1 + nober2;
            System.out.println("The Sum is " +sum);
        }    
    }

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Problem in BufferedReader

    Hello
    Firstly you have named your class BufferedReader, and you are doing a new BufferedReader. So, java is not looking in the BufferedReader default Library but for the constructor in your class. You have to rename the class. Taking about this part of the code.
    Code:
    public class BufferedReader
    {
        public static void main (String[]args)
        {
            BufferedReader dtln = new BufferedReader (new InputStreamReader(System.in));
           String no;      
            try
            {
                no = dtln.readLine();
                int nober1 = Integer.parseInt(no);
                no = dtln.readLine();
                int nober2 = integer.parseInt(no);
            }
    The second mistake is that you have defined two integers within a try statement and you are attempting to use them outside the try statement. Due to the scoping laws this can not be possible. So, please change that.
    Code:
    try
            {
                no = dtln.readLine();
                int nober1 = Integer.parseInt(no);
                no = dtln.readLine();
                int nober2 = integer.parseInt(no);
            }
            
            catch (IOException e)
            {
                System.out.println("Error!");
            }        
            
            int sum = nober1 + nober2;
            System.out.println("The Sum is " +sum);
    If you have any more queries do post back.

  3. #3
    Join Date
    Nov 2009
    Posts
    583

    Re: Problem in BufferedReader

    Hi
    Thanks for your reply. As you said I have changed the class name. Now the problem is with the last two line of the code. I really do not know about this, I am sorry but i ca not even guess what is the error related to. These are the two lines of my code.
    Code:
      int sum = number1 + number2;
     System.out.println("The Sum is " +sum);
    And the error it displays is
    Code:
    C:\Documents and Settings\shamed\javaprogs\src\BuffReadwww.java:35: cannot resolve symbol
    
    symbol : variable number1
    location: class BuffReadwww
    int sum = number1 + number2;
    
    C:\Documents and Settings\shamed\javaprogs\src\BuffReadwww.java:35: cannot resolve symbol
    
    symbol : variable number2
    
    location: class BuffReadwww
    
    int sum = number1 + number2;
    
    
    The system is out of resources.
    Consult the following stack trace for details.
    java.lang.OutOfMemoryError
    Any help on this. How can I fix this problem and what is this error all about?

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Problem in BufferedReader

    Hello
    The reason for the program issue is that your variable1 and variable2 are declared inside the try and catch block. That is why, they are not able to reach outside. Just do the following and your code will work.
    Code:
    try
            {
                no = dtln.readLine();
                int nober1 = Integer.parseInt(no);
                no = dtln.readLine();
                int nober2 = integer.parseInt(no);
    
                int sum = nober1 + nober2;
                System.out.println("The Sum is " +sum);
            } catch (IOException e) {
                System.out.println("Error!");
            }

Similar Threads

  1. Sony VGNCS3 laptop 15 inch screen problem...LCD or CHIP problem?
    By Mick$Tyler in forum Hardware Peripherals
    Replies: 5
    Last Post: 31-10-2010, 06:49 AM
  2. Replies: 4
    Last Post: 10-04-2010, 04:19 PM
  3. BufferedReader can not find file
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 27-02-2010, 05:14 AM
  4. Closing the bufferedreader
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 12:21 PM
  5. Problems with BufferedReader
    By Remedy in forum Software Development
    Replies: 5
    Last Post: 25-01-2010, 11:42 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,106,060.57444 seconds with 16 queries