Results 1 to 7 of 7
Thread: 'Cannot find symbol' error
- 10-10-2008, 03:26 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 7
- Rep Power
- 0
'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!!!!!
-
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.
- 10-10-2008, 03:46 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 7
- Rep Power
- 0
But I thought because I called the removeSubstring method by:
removeSubstring(withoutSub)
That i would be able to access variables from that method...
Thanks!
-
that would be an incorrect thought. The parameter variables passed have no knowledge of the inner workings of the method.
- 10-10-2008, 03:53 AM #5
Member
- Join Date
- Oct 2008
- Posts
- 7
- Rep Power
- 0
But I returned the value...
- 10-10-2008, 04:03 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 7
- Rep Power
- 0
AH HA! I figured it out! thanks so much for your help!!!
-
Similar Threads
-
Programm Error: cannot find symbol Help?
By junix in forum New To JavaReplies: 2Last Post: 12-10-2007, 05:30 AM -
cannot find symbol class error
By po0oker in forum New To JavaReplies: 5Last Post: 10-31-2007, 02:52 PM -
Error: cannot find symbol
By silvia in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:39 AM -
Error: cannot find symbol
By cachi in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:12 PM -
Error: cannot find symbol constructor
By zoe in forum New To JavaReplies: 1Last Post: 07-24-2007, 08:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks