package com.example.tictactoemain;
import com.example.tictactoelib.GameActivity;
import com.example.tictactoelib.GameView.State;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import com.example.tictactoelib.GameActivity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void startGame(boolean startWithHuman) {
Intent i = new Intent(this, GameActivity.class);
i.putExtra(GameActivity.EXTRA_START_PLAYER, startWithHuman ? State.PLAYER1.getValue() : State.PLAYER2.getValue());
startActivity(i);
}
}
游戏活动:
package com.example.tictactoelib;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.example.tictactoelib.GameView.State;
public class GameActivity extends Activity {
public static final String EXTRA_START_PLAYER =
"com.example.android.tictactoelib.GameActivity.EXTRA_START_PLAYER";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
在 MainActivity 我收到一个错误:
EXTRA_START_PLAYER cannot be resolved or is not a field.
主项目引用 tictactoelib 作为带有绿色复选框的库。tictactoelib 也被创建为一个库项目。尽管 EXTRA_START_PLAYER 被定义为公共静态最终字符串,但主项目似乎没有看到它。我正在拼凑 TicTacToe SDK android-17 项目,所以我正在尝试解决错误,尽管我还不明白问题出在哪里。
我也想知道的确切含义:="com.example.android.tictactoelib.GameActivity.EXTRA_START_PLAYER";
提前致谢...