dimanche 3 septembre 2017

Random Number not initialized

I have this code here:

    Random rand = new Random();
    int randomNum;
    int i;
    String[] text1 = getResources().getStringArray(R.array.text1);
    String[] text2 = getResources().getStringArray(R.array.text2);



    for(i = 0; i < ((MAX - 1)^(MAX - 1)); i++) {
        randomNum = rand.nextInt(2);
        // True wenn bereits angezeigt worden
        if(shown_table.get(randomNum)) {
            continue;
        }
        // False wenn noch nicht angezeigt worden
        else {
            break;
        }
    }

    // Texte anzeigen und Shown table auf true setzen.
    txt_text1.setText(text1[randomNum]);
    txt_text2.setText(text2[randomNum]);
    //shown_table.put(randomNum, true);

But when I compile it, I get this error:

Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
Error:(118, 33) error: variable randomNum might not have been initialized

when I put the " randomNum = rand.nextInt(2); " before the loop it works... but thats not what I want.

Any ideas why?

ps: I'm new to coding




Aucun commentaire:

Enregistrer un commentaire