Note that there are some explanatory texts on larger screens.

plurals
  1. PODuplicate local variable Object[] JOptionPane
    primarykey
    data
    text
    <p>I'm using JOptionPane in my code and i have this block:</p> <pre><code>Object[] move = { "Up", "Down" }; Object moveValue = JOptionPane.showInputDialog(null, "Where do you want to move?", "Input", JOptionPane.INFORMATION_MESSAGE, null, move, move[0]); </code></pre> <p>I'm using this above block multiple times and I was thinking, is there a way to give </p> <pre><code>Object[] move; </code></pre> <p>new values. When I try it like</p> <pre><code>Object[] move = { "Up", "Down", "Left" }; </code></pre> <p>it says <code>"Duplicate local variable move"</code> and when I try</p> <pre><code>move = { "Up", "Down", "Left" }; </code></pre> <p>it gives error <code>"Array constants can only be used in initializers"</code>.</p> <p>So is there a way for me to use my variable "move" multiple times?</p> <p>EDIT:</p> <p>Bigger part of the code is</p> <pre><code> while (true) { switch(hero.getPos()) { case 1: Object[] move = { "Up", "Down" }; Object moveValue = JOptionPane.showInputDialog(null, "Where do you want to move?", "Input", JOptionPane.INFORMATION_MESSAGE, null, move, move[0]); move = null; switch ((String) moveValue) { case "Üles": hero.setPos(hero.getPos() + 1); break; case "Paremale": hero.setPos(hero.getPos() + 5); break; } break; case 2: System.out.println("Draakon!!!!"); dragon = new Dragon(1); fight = new Fight(hero, dragon); break; case 3: System.out.println("hallo!"); move = { "Up", "Right", "Left" }; </code></pre> <p>So i have "move" defined on 4th row and also on the last one. Last one gives the error.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload