做一个简单的吐司工作

时间:2016-02-21 13:09:22

标签: java android toast

我有这个方法,应该在结尾输出一个吐司,但它会出现以下错误

  

无法解析方法Toast.makeText()

public Guess makeGuess() {

        PegEnum[] data1 = new PegEnum[4];



        PegEnum[] codeCpy = code.clone();
        PegEnum[] guessCpy = guess.clone();

        int correctCount = 0;
        int correctColourCount =0;
        for (int i = 0; i < codeCpy.length; i++) {
            if(codeCpy[i]==guessCpy[i]) {
                ++correctCount;
                codeCpy[i]=null;
                guessCpy[i]=null;
            }
        }

        for(int x =0; x<codeCpy.length; x++) {
            if (codeCpy[x]!=null) {
                for (int y = 0; y < guessCpy.length; y++) {
                    if (codeCpy[x]==guessCpy[y]) {
                        ++correctColourCount;
                        guessCpy[y]=null;
                    }
                }
            }
        }

        return new Guess(guess.clone(), correctCount, correctColourCount);


Toast.makeText(this, "You have guessed: " + correctCount + " Correct Pegs" + " and "
                        + correctColourCount + "Correct Colours", Toast.LENGTH_LONG).show();

}

1 个答案:

答案 0 :(得分:0)

您的代码中存在一些错误 -

1)您导入了Toast吗?2)您的吐司是在return语句之后,这使代码无法访问。