簡體   English   中英

Android中的錯誤:找不到符號方法

[英]Error in Android: Cannot find symbol method

我正在嘗試編譯以下代碼,但我不斷收到錯誤消息。

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;
    }
}

你要做的是

String abc="the quick red fox jumps over the lazy brown dog";

char[] sentenceToTest=abc.toCharArray();

而且您沒有在類中定義writeSuccess方法

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]);

   }


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

應該:

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

.toCharacterArray()是String對象的方法。 因此,您執行str.toCharacterArray() ,而不是toCharacterArray(str)

對於第二個問題,在顯示給我們的代碼中沒有實現writeSuccess()方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM