Results 1 to 10 of 10
- 11-06-2012, 04:13 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
Java Compile Error : cannot find symbol
Hi I need a little help please, I'm learning Java at Uni and this is a small program i'm working on, just need a little help working out this compile error, I'm using Textwrangler to write the code and and run it in terminal, please let me know if you need any further information to sort this out.
Program below:
/*SPELLCHECK (*)
Write a procedural program SpellCheck that checks if a word entered at the command line is correctly spelled.
Thanks to the Princeton Introduction to Programming in Java team,
http://introcs. cs.princeton.edu/java/data/ for providing the data.
Your program should compare the queried word to every word in the list.
If the word is misspelled, your program could offer suggestions in case of misspelling.
Use the Levenshtein distance to find close matches.
Here is an example specification, you may wish to write one for yourself.
Input: a word
Output: a list of suggestions if the word is misspelled.
Examples:
$ java Spellcheck misspelt
$ java Spellcheck mispelt
[misspelt]
$ java Spellcheck octopus
$ java Spellcheck octopuss
[octopus, octopuses, octopush, octopus's]
$
Algorithm Description:
1.user input a string
2.while string doesn't match string in wordlist
3.move onto next string in wordlist goto 2
4.if no match found, check similar words, max edit distance of 2
5.print them
*/
Java Code://imports import java.util.*; import java.util.Locale; import java.io.*; import java.util.Scanner; public class Spellcheck { public static void main (String[] args) { System.out.println("what the string args contains ="+ Arrays.toString(args));// readFile("words.utf-8.txt"); //System.out.println("readfile says =" + Arrays.toString(readFile("words.utf-8.txt"))); int match = args.equalsIgnoreCase(readFile("words.utf-8.txt")); System.out.println("Returned Value " + match ); //while ((args = readFile("words.utf-8.txt"))) != null); }//Main public static int editDistance(String s, String t){ //code for working out the edit distance (difference) between two strings //taken from [url=http://professorjava.weebly.com/edit-distance.html]Edit Distance - Professor Java[/url] int m=s.length();//creating variable to store length of string s int n=t.length();//creating variable to store length of string t int[][]d=new int[m+1][n+1];//creating a matrix with the variables of the lengths of strings for(int i=0;i<=m;i++){ d[i][0]=i; }//for for(int j=0;j<=n;j++){ d[0][j]=j; }//end of for loop //end of creating matrix for(int j=1;j<=n;j++){//count through j up to length for(int i=1;i<=m;i++){//count through i up to length if(s.charAt(i-1)==t.charAt(j-1)){//compare each character in the two strings, if equal... d[i][j]=d[i-1][j-1];// }//if else{ d[i][j]=min((d[i-1][j]+1),(d[i][j-1]+1),(d[i-1][j-1]+1)); }//else }//for }//for return(d[m][n]); }//editDistance public static int min(int a,int b,int c){//program to return minimum value from 3 integers return(Math.min(Math.min(a,b),c)); } public static String[] readFile(String filename) { //taken from [url=http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html]Stupid Scanner tricks... | Java.net[/url] try { String text = new Scanner(new File(filename)). useDelimiter("\\A").next(); return text.trim().split("\\s+"); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }//String readFile }//ClassLast edited by JoelC; 11-06-2012 at 04:58 PM. Reason: formatting
- 11-06-2012, 04:28 PM #2
Re: Java Compile Error : cannot find symbol
Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!
Forum Rules
Guide For New Members
BB Code List - Java Programming Forum
I have added the tags for you this time.
Please provide us the errors you are getting!
- 11-06-2012, 04:37 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Java Compile Error : cannot find symbol
... and highlight the line it's happening on.
Please do not ask for code as refusal often offends.
- 11-06-2012, 04:42 PM #4
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
Re: Java Compile Error : cannot find symbol
Hey thanks what a warm welcome, ah ok code tags that's how you do it. cheers i will next time.
sorry i completely missed out the error, below is what terminal said...
1 error
ErAsErHeAd:pap Joel_Greti$ javac Spellcheck.java
Spellcheck.java:50: cannot find symbol
symbol : method equalsIgnoreCase(java.lang.String[])
location: class java.lang.String[]
int match = args.equalsIgnoreCase(readFile("words.utf-8.txt"));
^
it doesn't seem to like the equalsIgnoreCase(), in the first block of code, though i got it compile before so really can't work out why?
thanks in advance for your help.
- 11-06-2012, 04:54 PM #5
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
Re: Java Compile Error : cannot find symbol
oh and the little arrow points at the dot between the args.equalsIgnoreCase()
- 11-06-2012, 05:07 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Java Compile Error : cannot find symbol
args is a String[], not a String.
Please do not ask for code as refusal often offends.
- 11-06-2012, 05:13 PM #7
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
Re: Java Compile Error : cannot find symbol
ah so does that mean that i cannot use the equalsIgnoreCase() method?, thanks Tolls I will look for some other way of comparing.
- 11-06-2012, 05:24 PM #8
Re: Java Compile Error : cannot find symbol
Correct, at least not in that way. If you want to compare one simple string to another, then this method is fine! But if you need to compare two arrays of strings and ensure that both arrays contain the same strings, then you need to loop through the array and compare for each index. If you only care about the first item in the array, then just access that item:so does that mean that i cannot use the equalsIgnoreCase() method?
Java Code:assert "someInput".equalsIgnoreCase(args[0]);
- 11-06-2012, 05:36 PM #9
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
Re: Java Compile Error : cannot find symbol
Brilliant thank you for clearing that up, I am trying to compare one string from args with a string array to see if there are any matches, could you possibly suggest a good method to use? and could you confirm that I'd have to loop through the string array to check each string? I'm trying out Arrays.binarySearch(object[], object value) at the moment. Do you know if I am heading in the right direction?
thanks for all your help
- 11-06-2012, 07:43 PM #10
Re: Java Compile Error : cannot find symbol
Unless your inputs are sorted, binary search won't work. However, unless your input is millions of lines, that doesn't matter.
I would just use a simple loop that looks through the whole input set, so for example:
If you need to compare a list to a list, you can do the same thing with a nested loop. There are more efficient ways to do it involving data structures, but again, if the list sizes are small, it won't matter!Java Code:public class Test { /** * @param args the command line arguments */ public static void main(String[] args) { new Test(); } public Test(){ String[] args = {"A", "B", "C"}; for(String str : args){ if(str.equalsIgnoreCase("B")){ System.out.println("I found it!"); break; } } } }
Similar Threads
-
I'm getting CustomerTest.java:38: error: cannot find symbol when i try to compile
By vcardell in forum New To JavaReplies: 1Last Post: 11-18-2011, 11:55 PM -
Cannot find symbol (compile error)
By mrgreenacid in forum New To JavaReplies: 1Last Post: 10-30-2011, 04:55 AM -
Cannot find symbol (compile error)
By mrgreenacid in forum Java SoftwareReplies: 2Last Post: 10-30-2011, 03:42 AM -
USing JGrasp to Compile and receiving Cannot find symbol
By johnb082 in forum New To JavaReplies: 6Last Post: 06-23-2011, 10:37 PM -
Constructor: Cannot find symbol compile error.
By CaptainBeer in forum New To JavaReplies: 4Last Post: 04-28-2011, 11:25 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks