Java x无法解析或不是字段

Java x无法解析或不是字段,java,android,eclipse,Java,Android,Eclipse,所以我刚刚开始编程,即将发布我的第一个应用程序,对此我感到非常高兴。剩下的6个错误是“玩家1/玩家2无法解决或不是场”。所有六个错误都是相同的,3个是玩家1的错误,3个是玩家2的错误。我肯定忘了编写代码,但我不知道是什么。我已经指出了所有的错误,它们在下面几行:108、150、158、191、195和245 My MainActivity.java: package com.wouter.testjk; import android.app.Activity; import android.

所以我刚刚开始编程,即将发布我的第一个应用程序,对此我感到非常高兴。剩下的6个错误是“玩家1/玩家2无法解决或不是场”。所有六个错误都是相同的,3个是玩家1的错误,3个是玩家2的错误。我肯定忘了编写代码,但我不知道是什么。我已经指出了所有的错误,它们在下面几行:108、150、158、191、195和245

My MainActivity.java:

package com.wouter.testjk;


import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;

import com.wouter.testjk.R;


public class MainActivity extends Activity implements OnClickListener{

    private TicTacToeGame mGame;

    private Button mBoardButtons[];

    private TextView mInfoTextView;
    private TextView mPlayeroneCount;
    private TextView mTieCount;
    private TextView mPlayertwoCount;
    private TextView mPlayeroneText; 
    private TextView mPlayertwoText;

    private int mPlayeroneCounter = 0;
    private int mTieCounter = 0;
    private int mPlayertwoCounter = 0;

    private boolean mPlayeroneFirst = true;
    private boolean mIsSinglePlayer = false;
    private boolean mIsPlayerOneTurn = true;
    private boolean mGameOver = false;

    @Override
        protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        boolean mGameType = getIntent().getExtras().getBoolean("gametype");

        mBoardButtons = new Button[mGame.getBOARD_SIZE()];
        mBoardButtons[0] = (Button) findViewById(R.id.one);
        mBoardButtons[1] = (Button) findViewById(R.id.two);
        mBoardButtons[2] = (Button) findViewById(R.id.three);
        mBoardButtons[3] = (Button) findViewById(R.id.four);
        mBoardButtons[4] = (Button) findViewById(R.id.five);
        mBoardButtons[5] = (Button) findViewById(R.id.six);
        mBoardButtons[6] = (Button) findViewById(R.id.seven);
        mBoardButtons[7] = (Button) findViewById(R.id.eight);
        mBoardButtons[8] = (Button) findViewById(R.id.nine);

        Button mTen = (Button) findViewById(R.id.ten);
        mTen.setOnClickListener(this);
        Button mEleven = (Button) findViewById(R.id.eleven);
        mEleven.setOnClickListener(this);



        mInfoTextView = (TextView) findViewById(R.id.information);
        mPlayeroneCount = (TextView) findViewById(R.id.humancount);
        mTieCount = (TextView) findViewById(R.id.tiesCount);
        mPlayertwoCount = (TextView) findViewById(R.id.androidCount);
        mPlayeroneText = (TextView) findViewById(R.id.human);
        mPlayertwoText = (TextView) findViewById(R.id.android);

        mPlayeroneCount.setText(Integer.toString(mPlayeroneCounter));
        mTieCount.setText(Integer.toString(mTieCounter));
        mPlayeroneCount.setText(Integer.toString(mPlayertwoCounter));

        mGame = new TicTacToeGame();

        startNewGame(mGameType);

    }

    private void startNewGame(boolean isSingle)
    {
        this.mIsSinglePlayer = isSingle;

        mGame.clearBoard();

        for (int i = 0; i < mBoardButtons.length; i++)
        {
            mBoardButtons[i].setText("");
            mBoardButtons[i].setEnabled(true);
            mBoardButtons[i].setOnClickListener(new ButtonClickListener(i));

        }
        if (mIsSinglePlayer)
        {
             mPlayeroneText.setText("speler: ");
             mPlayertwoText.setText("android: ");

             if (mPlayeroneFirst)
             {
                 mInfoTextView.setText(R.string.first_human);
                 mPlayeroneFirst = false;
             }
             else
             {
                 mInfoTextView.setText(R.string.turn_computer);
                 int move = mGame.getComputerMove();
                 setMove(mGame.PLAYER_TWO, move); //error here
                 mPlayeroneFirst = true;
             }
        }
        else
        {
             mPlayeroneText.setText("speler 1: ");
             mPlayertwoText.setText("speler 2: ");

             if (mPlayeroneFirst)
             {
                 mInfoTextView.setText(R.string.turn_player_one);
                 mPlayeroneFirst = false;
             }
             else
             {
                 mInfoTextView.setText(R.string.turn_player_two);
                 mPlayeroneFirst = true;
             }

        }

        mGameOver = false;
    }

    private class ButtonClickListener implements View.OnClickListener
    {
        int location;

        public ButtonClickListener(int location)
        {
            this.location = location;
        }

        @Override
        public void onClick(View view) {
            if (!mGameOver)
            {
                if(mBoardButtons[location].isEnabled())
                {
                    if(mIsSinglePlayer)
                    {
                         setMove(mGame.PLAYER_ONE, location); //error here

                         int winner = mGame.checkForWinner();

                         if (winner == 0)
                         {
                             mInfoTextView.setText(R.string.turn_computer);
                             int move = mGame.getComputerMove();
                             setMove(mGame.PLAYER_TWO, move); //error here
                             winner = mGame.checkForWinner();

                         }
                         if (winner == 0)
                                 mInfoTextView.setText(R.string.turn_human);
                         else if (winner == 1)
                         {
                             mInfoTextView.setText(R.string.result_tie);
                             mTieCounter++;
                             mTieCount.setText(Integer.toString(mTieCounter));
                             mGameOver = true;
                         }       
                         else if (winner ==2)
                         {
                             mInfoTextView.setText(R.string.result_human_wins);
                             mPlayeroneCounter++;
                             mPlayeroneCount.setText(Integer.toString(mPlayeroneCounter));
                             mGameOver = true;
                         }
                         else if (winner ==3)
                         {
                             mInfoTextView.setText(R.string.result_android_wins);
                             mPlayertwoCounter++;
                             mPlayertwoCount.setText(Integer.toString(mPlayertwoCounter));
                             mGameOver = true;
                         }

                    }
                    else
                    {
                        if(mIsPlayerOneTurn)
                        {
                            setMove(mGame.PLAYER_ONE, location); //error here
                        }
                        else
                        {setMove(mGame.PLAYER_TWO, location); //error here

                        }


                        int winner = mGame.checkForWinner();

                        if (winner == 0)
                        {
                            if(mIsPlayerOneTurn)
                            {
                                mInfoTextView.setText(R.string.turn_player_two);
                                mIsPlayerOneTurn = false;
                            }
                            else
                            {
                                mInfoTextView.setText(R.string.turn_player_one);
                                mIsPlayerOneTurn = true;
                            }
                        }
                        else if (winner == 1)
                        {
                            mInfoTextView.setText(R.string.result_tie);
                            mTieCounter++;
                            mTieCount.setText(Integer.toString(mTieCounter));
                            mGameOver = true;
                        }       
                        else if (winner ==2)
                        {
                            mInfoTextView.setText(R.string.player_one_wins);
                            mPlayeroneCounter++;
                            mPlayeroneCount.setText(Integer.toString(mPlayeroneCounter));
                            mGameOver = true;
                        }
                        else if (winner ==3)
                        {
                            mInfoTextView.setText(R.string.player_two_wins);
                            mPlayertwoCounter++;
                            mPlayertwoCount.setText(Integer.toString(mPlayertwoCounter));
                            mGameOver = true;
                     }
                    }
                }
            }    
        }
    }

    private void setMove(char player, int location)
    {
        mGame.setMove(player,location);
        mBoardButtons[location].setEnabled(false);
        mBoardButtons[location].setText(String.valueOf(player));
        if (player == mGame.PLAYER_ONE) //error here
            mBoardButtons[location].setTextColor(Color.GREEN);
        else
        {
            mBoardButtons[location].setTextColor(Color.RED);
        }
    }

    @Override
    public void onClick(View view) {

        switch (view.getId())
        {
        case R.id.ten:

            startNewGame(mIsSinglePlayer);
            return;

        case R.id.eleven:

            MainActivity.this.finish();
            return;

        }
    }
}
package com.wouter.testjk;
导入android.app.Activity;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.view.view;
导入android.view.view.OnClickListener;
导入android.view.Window;
导入android.widget.Button;
导入android.widget.TextView;
导入com.wouter.testjk.R;
公共类MainActivity扩展活动实现OnClickListener{
私人游戏机;
专用按钮[];
私有文本视图mInfoTextView;
私有文本视图mPlayeroneCount;
私有文本视图mTieCount;
私有文本视图mPlayertwoCount;
私有文本视图mPlayeroneText;
私有文本视图mPlayertwoText;
private int mPlayeroneCounter=0;
私有int mTieCounter=0;
private int mPlayertwoCounter=0;
私有布尔值mPlayeroneFirst=true;
private boolean-player=false;
私有布尔mIsPlayerOneTurn=true;
私有布尔值mGameOver=false;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.activity_main);
boolean mGameType=getIntent().getExtras().getBoolean(“游戏类型”);
mBoardButtons=新按钮[mGame.getBOARD_SIZE()];
mBoardButtons[0]=(按钮)findViewById(R.id.one);
mBoardButtons[1]=(按钮)findViewById(R.id.two);
mBoardButtons[2]=(按钮)findViewById(R.id.three);
mBoardButtons[3]=(按钮)findViewById(R.id.four);
mBoardButtons[4]=(按钮)findViewById(R.id.five);
mBoardButtons[5]=(按钮)findViewById(R.id.six);
mBoardButtons[6]=(按钮)findViewById(R.id.seven);
mBoardButtons[7]=(按钮)findViewById(R.id.eight);
mBoardButtons[8]=(按钮)findViewById(R.id.nine);
按钮mTen=(按钮)findViewById(R.id.ten);
mTen.setOnClickListener(此);
按钮mEleven=(按钮)findViewById(R.id.eleven);
mEleven.setOnClickListener(这个);
mInfoTextView=(TextView)findViewById(R.id.information);
mPlayeroneCount=(TextView)findViewById(R.id.humancount);
mTieCount=(TextView)findViewById(R.id.tiesCount);
mPlayertwoCount=(TextView)findViewById(R.id.androidCount);
mPlayeroneText=(TextView)findViewById(R.id.human);
mPlayertwoText=(TextView)findViewById(R.id.android);
setText(Integer.toString(mPlayeroneCounter));
setText(Integer.toString(mTieCounter));
mPlayeroneCount.setText(Integer.toString(mPlayertwoCounter));
mGame=新的TictoEgame();
StartNewName(mGameType);
}
私有void startNewName(布尔isSingle)
{
this.mIsSinglePlayer=isSingle;
mGame.clearBoard();
对于(int i=0;ipackage com.wouter.testjk;

import java.util.Random;

public class TicTacToeGame {

    private char mBoard[];
    private final static int BOARD_SIZE = 9;

    public static final char PLAYER_ONE = 'X';
    public static final char PLAYER_TWO = '0';
    public static final char EMPTY_SPACE = ' ';

    private Random mRand;

    public static int getBOARD_SIZE() {
        return BOARD_SIZE;
    }

    public TicTacToeGame(){
        mBoard = new char[BOARD_SIZE];

        for (int i = 0; i < BOARD_SIZE; i++)
            mBoard[i] = EMPTY_SPACE;

        mRand = new Random();
    }

    public void clearBoard()
    {
        for (int i = 0;i < BOARD_SIZE; i++)
        {
            mBoard[i] = EMPTY_SPACE;
        }
    }

    public void setMove(char player, int location)
    {
        mBoard[location] = player;
    }

    public int getComputerMove()
    {
        int move;

        for (int i = 0; i < getBOARD_SIZE(); i++)
        {
            if (mBoard[i] != PLAYER_ONE && mBoard[i] != PLAYER_TWO)
            {
                char curr = mBoard[i];
                mBoard[i] = PLAYER_TWO;
                if (checkForWinner() == 3)
                {
                    setMove(PLAYER_TWO, i);
                    return i;
                }
                else 
                    mBoard[i] = curr;
            }
        }
        for (int i = 0; i < getBOARD_SIZE(); i++)
        {
            if (mBoard[i] != PLAYER_ONE && mBoard[i] != PLAYER_TWO)
            {
                char curr = mBoard[i];
                mBoard[i] = PLAYER_ONE;
                if (checkForWinner() == 2)
                {
                    setMove(PLAYER_TWO, i);
                    return i;
                }
                else 
                    mBoard[i] = curr;
            }
        }
        do
        {
            move = mRand.nextInt(getBOARD_SIZE());
        }while (mBoard[move]==PLAYER_ONE || mBoard[move] == PLAYER_TWO);

            setMove(PLAYER_TWO, move);
        return move;
    }
    public int checkForWinner()
    {
        for (int i=0;i<=6;i+=3)
        {
            if (mBoard[i] == PLAYER_ONE && 
                mBoard[i+1] == PLAYER_ONE && 
                mBoard[i+2] == PLAYER_ONE)
                return 2;
            if (mBoard[i] == PLAYER_TWO && 
                mBoard[i+1] == PLAYER_TWO && 
                mBoard[i+2] == PLAYER_TWO)
                return 3;
        }
        for (int i = 0; i <=2; i++)
        {
            if (mBoard[i] == PLAYER_ONE &&
                mBoard[i+3] == PLAYER_ONE &&
                mBoard[i+6] == PLAYER_ONE)
                return 2;
            if (mBoard[i] == PLAYER_TWO &&
            mBoard[i+3] == PLAYER_TWO &&
            mBoard[i+6] == PLAYER_TWO)
                return 3;

        }
        if((mBoard[0] == PLAYER_ONE &&
                mBoard[4] == PLAYER_ONE &&
                mBoard[8] == PLAYER_ONE)|| 
                (mBoard[2] == PLAYER_ONE &&
                mBoard[4] == PLAYER_ONE &&
                mBoard[6] == PLAYER_ONE))
        return 2;
    if((mBoard[0] == PLAYER_TWO &&
            mBoard[4] == PLAYER_TWO &&
            mBoard[8] == PLAYER_TWO)|| 
            (mBoard[2] == PLAYER_TWO &&
            mBoard[4] == PLAYER_TWO &&
            mBoard[6] == PLAYER_TWO))
        return 3;


    for (int i = 0; i < getBOARD_SIZE(); i++)
    {
        if (mBoard[i] != PLAYER_ONE && mBoard[i] != PLAYER_TWO)
            return 0;
    }
    return 1;
    }
}