我是android的新手我正在开发游戏tic tac toe但是当我在模拟器上运行它时说tic tac toe已经停止工作了。我不知道什么是错的。我的代码没有错误。
这是我的主要活动类代码:
public class MainActivity extends AppCompatActivity {
Button btn_one;
Button btn_two;
int myVeriable=0,player1Score=0,player2Score=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_one= (Button) findViewById(R.id.one);
btn_two= (Button) findViewById(R.id.two);
}
private void one_Click(View myView)
{
if(!b1)
{
if(meraVeriable%2==0)
{
btn_one.setText("O");
}
else
{
btn_one.setText("X");
}
}
}
private void two_Click(View myView)
{
if(!b2)
{
if(meraVeriable%2==0)
{
btn_two.setText("O");
}
else
{
btn_two.setText("X");
}
}
}
}
这是我的xml代码:
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/one"
android:textStyle="bold"
android:textColor="#fedc00"
android:onClick="one_Click"/>
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/two"
android:textStyle="bold"
android:textColor="#fedc00"
android:onClick="two_Click" />
这是log cat屏幕截图:
答案 0 :(得分:1)
我的代码没有错误。
假。您的点击方法需要公开
public void one_Click(View myView) {
...
}
public void two_Click(View myView) {
...
}
您的错误清楚地表明无法找到该方法。因此,公开它将使它被发现。