Results 1 to 7 of 7
  1. #1
    minihazard10 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default 'Cannot find symbol' error

    Hey,

    I have no idea why I am getting this error message. The variable is properly defined and spelled correctly and everything seems like it should work. I am at my wit's end!!!!
    Any help would be much appreciated!!!

    The relevant parts of the code:

    import java.util.*;

    public class StringManipulator {

    public static void main(String[] args){
    Scanner console = new Scanner(System.in);
    System.out.println("Please enter a word, and a substring found in that word, separated by a space:");
    String str1 = console.next();
    String str2 = console.next();
    System.out.println("Removing " + str2 +" from " + str1 + " gives: " + removeSubstring(withoutSub));

    }

    public static String removeSubstring(String str1, String str2) {
    int i = str1.indexOf(str2);
    int subLength = str2.length();
    String first = str1.substring(0, i);
    String second = str1.substring(i + subLength);
    String withoutSub = first + second;
    return withoutSub;

    }
    }


    The error message:
    Error: cannot find symbol
    symbol : variable withoutSub
    location: class StringManipulator


    Thank you!!!!!

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

    Default

    withoutSub is declared in the removeSubstring method and thus will only be visible within this method and no-where else. Also, it looks like you need to pass two strings into the removeSubstring method, not one.

  3. #3
    minihazard10 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default

    But I thought because I called the removeSubstring method by:

    removeSubstring(withoutSub)

    That i would be able to access variables from that method...

    Thanks!

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

    Default

    that would be an incorrect thought. The parameter variables passed have no knowledge of the inner workings of the method.

  5. #5
    minihazard10 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default

    But I returned the value...

  6. #6
    minihazard10 is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default

    AH HA! I figured it out! thanks so much for your help!!!

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

Similar Threads

  1. Programm Error: cannot find symbol Help?
    By junix in forum New To Java
    Replies: 2
    Last Post: 12-10-2007, 06:30 AM
  2. cannot find symbol class error
    By po0oker in forum New To Java
    Replies: 5
    Last Post: 10-31-2007, 03:52 PM
  3. Error: cannot find symbol
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:39 AM
  4. Error: cannot find symbol
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:12 PM
  5. Error: cannot find symbol constructor
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 09:24 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
  •