Hello, complete Java (and programming in general) newbie here.
I'm working on a small program that asks the user's name, then greets him/her. I'm getting extremely frustrated with my inability to make showInputDialog play nicely with custom icons. The input box works perfectly without the custom icon. I also have no trouble with the other JOptionPane methods, it's just InputDialog that throws a hissy fit whenever I try to implement a custom icon and I can't figure out why. I'm also confused about how to define the string that the user inputs.
This is what my code looks like for now:
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
class Excercise1 {
public static void main(String[] args) {
String s;
ImageIcon icon = new ImageIcon("Images/r2d2.jpg");
Object ob = JOptionPane.showInputDialog(null,"What is your name?","R2-D2 says:",JOptionPane.QUESTION_MESSAGE,icon);
System.out.println("Hello "+ s +"!");
}
}
With the icon part in, my compiler starts complaining about not finding a symbol followed by a bunch of nonsensical gibberish that I don't understand. If I take it out along with the System.out.println line, the program runs fine. For the last line my compiler complains that variable s may not have been initialized, which is bull, as I clearly define it as a String.
Someone, please direct me to the correct path. I'm losing my hair with this infuriating language! >_<