1. Check out our companion app, Forums for Android! Download from Google Play

Android Application Problem

Discussion in 'Android Apps & Games' started by anthony.timotheou, Oct 5, 2010.

  1. anthony.timotheou

    anthony.timotheou New Member
    Thread Starter

    Sep 19, 2010
    Check this class below,

    ______ My Code _______

    public class Main extends Activity implements OnKeyListener {
    DisplayWord currentWord;
    TextView wordStatus;
    EditText inputWord;
    Button okBtn;
    int pos = 1;
    char currentChar;
    char inputChar;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

    currentWord = (DisplayWord) this.findViewById(R.id.trueWord);
    currentWord.setText("Bonjure"); // word from database

    wordStatus = (TextView) this.findViewById(R.id.wordStatus);

    inputWord = (EditText) this.findViewById(R.id.wordInput);

    public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (inputWord.getText().toString().length() <= currentWord.getText().toString().length()) {
    pos = inputWord.getText().toString().length();
    currentChar = currentWord.getText().toString().charAt(pos);
    inputChar = inputWord.getText().toString().charAt(pos);

    } return false;
    _____ END _____

    When running this code, upon entering data into the input box it causes an exception straight away and for the program exit unexpectedley.

    I am trying to extract the input word from EditText field and the word stored in a TextView and to compare them char by char as those chars are entered into the input box, sort of a word game, where the character will be highlighted green if it is correct and red if it is not.

    I have no idea why this behaviour happens, I can see in debugger an StringIndexOutOfBounds exception, and a ResourceNotFound when I have been tampering with different ways of attempting this.

    Any advice or links appreciated,


Share This Page