import javax.swing.JOptionPane;
public class SpeedOfSound {
public static void main(String[] args) {
String medium;
double time = 0;
double distance = 0;
medium = JOptionPane.showInputDialog("Please enter a medium\n" + "(air, water, steel)");
distance = Double.parseDouble(JOptionPane.showInputDialog("Please enter the distance the soundwave has to travel"));
if (medium.equalsIgnoreCase("air")) {
time = distance / 1100;
} else if (medium.equalsIgnoreCase("water")) {
time = distance / 4900;
} else if (medium.equalsIgnoreCase("steel")) {
time = distance / 16400;
}
System.out.println(time);
System.exit(0);
}
}
I've never encountered this error and I can't point out what it even is given the code. Any help would be appreciated. Thanks.
Edit: someone mentioned that the question is a duplicate. I looked at that question before posting this. Again, I don't understand the context of my error. The previous question says the exception happens when the pointer points to "null" I can't seem to find an instance where I don't have anything pointing to the respective values.