0

So clearly I am not familiar with java, I am having problems with the variables the problem is that I cannot change the value of the row and column and the elements are not adding in the ArrayList here id the code. these is how I declared my variable.

// variables to be used
public int row ,col;
public char[][] board;
public ArrayList<String> converted_board;
public ArrayList<String> toUseWords;
public ArrayList<String> toUseDescription;
public ArrayList<String> inUse = new ArrayList<>();
public Random randomizer = new Random();

// Create instances of categories
private Words easyCategory = new Words(easyLetterWord, easyDescription);
private Words normalCategory = new Words(normalLetterWord, normalDescription);
private Words hardCategory = new Words(hardLetterWord, hardDescription);

this is the my problem

    // get game mode easy = 4, normal = 5, hard = 6 letters
    if (gameMode.toLowerCase() == "easy mode") {
        row = 8;
        col = 4;
        toUseWords = getToUseWords(easyCategory.getWord(), toUseWords, inUse, row);
        toUseDescription = getWordDefinitions(easyCategory.getWord(), toUseWords, easyCategory.getDesription());
    }
    else if (gameMode.toLowerCase() == "normal mode"){
        row = 6;
        col = 5;
        toUseWords = getToUseWords(normalCategory.getWord(), toUseWords, inUse, row);
        toUseDescription = getWordDefinitions(normalCategory.getWord(), toUseWords, normalCategory.getDesription());
    }
    else if (gameMode.toLowerCase() == "hard mode"){
        row = 6;
        col = 6;
        toUseWords = getToUseWords(hardCategory.getWord(), toUseWords, inUse, row);
        toUseDescription = getWordDefinitions(hardCategory.getWord(), toUseWords, hardCategory.getDesription());

    //convert 2D array to 1D array to be passed in in the adapter
    // converted_board = board_convert(board);

    // for debugging purposes
    description_display.setText(String.valueOf(row));

somehow the output is 0 when I try to display the row and the sizes of the ArrayList in the textview

1 Answers1

1

I see two things which might be your problem.

  1. comparing strings in java should be done with the String.equals() method, not the == operator. The == operator doesn't compare the contents of the strings, rather the object 'pointers' - which are often not the same. i.e. you want to do this for the 3 string compares:

    if( "easy mode".equals(gameMode.toLowerCase() )

  2. I don't see a closing brace on the 3rd if/else statement

I'd recommend also setting a breakpoint and stepping through the code and/or put some System.out calls so you can see what branches are being executed, or not and print out the state at various points to help you debug it.

crig
  • 859
  • 6
  • 19