-1

i new in android i am working on game tic tac toe but when i run it on emulator it says tic tac toe has stop working. i don't know whats going wrong. my code has no errors.

This is my mainactivity class code:

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

}

This is my xml code:

<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" />

this is log cat screen shot:

logcat

  • 3
    Could you post the stack trace? Also, there's no variables `b1`, `b2` or `meraVeriable`. Either you left these out or your code shouldn't compile. – manabreak Mar 19 '16 at 15:17
  • Use the debugger and find out where the crash occurs. – Cijo Mar 19 '16 at 15:20
  • Possible duplicate of [Unfortunately MyApp has stopped. How can I solve this?](http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this) – OneCricketeer Mar 19 '16 at 15:35

1 Answers1

1

my code has no errors.

False. Your click methods need to be public

public void one_Click(View myView) {
   ...
}

public void two_Click(View myView) {
   ...
}

Your error clearly says the method cannot be found. Therefore, making it public will make it be found.

OneCricketeer
  • 126,858
  • 14
  • 92
  • 185