0

I am trying to compile the following code but I keep getting the error.

Cannot find symbol method toCharacterArray(string)
Cannot find symbol method writeSuccess(int,char[],char[])

public class ControlFlow { char[] alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; public void start(){ char[] sentenceToTest = toCharacterArray("the quick red fox jumps over the lazy brown dog"); char[] missingLetters = new char[26]; int numOfMissingLetters = 0; for(int i=0; i < alphabet.length; i++){ char letterToFind = alphabet[i]; if(hasLetter(letterToFind, sentenceToTest)){ missingLetters[numOfMissingLetters] = letterToFind; numOfMissingLetters++; } } writeSuccess(numOfMissingLetters,missingLetters,sentenceToTest); } public boolean hasLetter(char aLetter, char[] aSentence) { boolean found = false; int position = 0; while(!found){ if(aLetter == aSentence[position]){ found = true; }else if(position == aSentence.length - 1){ break; }else{ position++; } } return found; } } 

2 Answers 2

1
char[] sentenceToTest = toCharacterArray("the quick red fox jumps over the lazy brown dog"); 

Should be:

char[] sentenceToTest = "the quick red fox jumps over the lazy brown dog".toCharacterArray(); 

.toCharacterArray() is a method of the String object. So you do str.toCharacterArray(), not toCharacterArray(str).

For your second issue, you don't have a writeSuccess() method implemented in the code you're showing us.

Sign up to request clarification or add additional context in comments.

1 Comment

@BradHazelnut Glad I could help! I'm not sure about the second problem, that code is not included in what you showed us. I could help you more with that if you show it to me. I suspect that there's a parameter mismatch.
1

waht you have to do is

String abc="the quick red fox jumps over the lazy brown dog"; char[] sentenceToTest=abc.toCharArray(); 

and you dont have writeSuccess method defined in your class

public void writeSuccess (int numOfMissingLetters,char[] missingLetters, char[] sentenceToTest){ Log.e("","number of missing letters are : "+numOfMissingLetters); Log.e("","------------------"); for(int i=0 ;i<sentenceToTest.length();i++){ Log.e("","sentence to test is : "+sentenceToTest[i]); } Log.e("","------------------"); for(int i=0 ;i<missingLetters.length();i++){ Log.e("","missing letter is : "+missingLetters[i]); } } 

12 Comments

awesome, that fixed that error, thank you, but now i am only getting the writesuccess error
You didn't answer the second part of the question. Also, could you explain your answer?
@BradHazelnut you havent defined your method in your class
@BradHazelnut Could you tell what this method is for writesuccess ?
from the tutorial, its just supposed write to the output log that it was a success
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.