PLUR PLUR - 1 year ago 52
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;
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");
}else if (command == League);
}else if (command == Steam);
Runtime.getRuntime().exec("\"C:/Program Files (x86)/Steam/Steam.exe\"");




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 Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download