PLUR PLUR - 26 days ago 8
Java Question

Receiving an 'else' without 'if' error

import javax.swing.JOptionPane;
public class Cortana2
{
public static void main(String[] args) throws Exception
{
//Declaring Variables (Add more commands)
String command;
// Command will always stay the same
// All strings below are commands to put in
String Steam;
String League;
League=("League");
Steam=("Steam");
command= JOptionPane.showInputDialog("Give a valid command");

{
if (command == null);
{
JOptionPane.showMessageDialog(null, "This is not a valid command. If you have forgotten what commands are valid, please refer to Devon for assistance");
JOptionPane.getRootFrame().dispose();
}else if (command == League);
{
Runtime.getRuntime().exec("\"D:/LeagueClient.exe\"");
}else if (command == Steam);
{
Runtime.getRuntime().exec("\"C:/Program Files (x86)/Steam/Steam.exe\"");
}

System.exit(0);
}

}


}

Not 100% sure why I'm getting the error. I've seen where others said to remove the semicolons from the 'if' statements but then nothing executes when I run the program and type in commands. Sorry if anything seems poorly formatted.

Answer
if (command == null);

Don't put a ";" at the end of your if/else statements.

but then nothing executes when I run the program and type in commands

Don't use == to compare String.

Instead use the String.equals(...) method

Also variable names should NOT start with an upper case character.