0

I am trying to add an image to my JOptionPane and I have been piecing things together to see if it will work but I am getting a NullPointerException

Here is my code:

public class MonitoringSystem {

public static void main(String[] a) throws IOException, UnSupportedLookAndFeelException{

FileInputStream fileBytesStream = null;
Scanner inFS = null;
{
{
try{

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException | InstantiationException |     IllegalAccessException | UnsupportedLookAndFeelException ex) {
            }

ImageIcon icon = new ImageIcon(MonitoringSystem.class.getResource        ("C:\\Users\\Zoltek\\Desktop\\Zoo.jpg"));

Object[] options = {"Animals","Habitats","Exit"};
int n = JOptionPane.showOptionDialog(null,
        "Zookeepers would you like to view animal activities or monitor        habitats?",
        "Welcome to the Brooklyn Zoo!",
        JOptionPane.YES_NO_CANCEL_OPTION,
        icon,
        options,
        options[1]);  

System.out.println(n);  

JFrame animal = new JFrame("Animals");  
JFrame habitat = new JFrame("Habitats"); 

if(n==0){  
 animal.setVisible(true); 
String[] choices = {"Lions","Bears","Giraffes"};
String input = (String) JOptionPane.showInputDialog(null,"Select  Animal:","Zoo Animals",
JOptionPane.QUESTION_MESSAGE,null,choices,choices[1]);
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
smenon
  • 1
  • 6
  • 1) See [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/q/3988788/418556) & [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/q/218384/418556) 2) Always copy/paste error and exception output! 3) Use a logical and consistent form of indenting code lines and blocks. The indentation is intended to make the flow of the code easier to follow! 4) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Apr 13 '17 at 15:36
  • .. 5) A single blank line of white space in source code is all that is *ever* needed. Blank lines after `{` or before `}` are also typically redundant. – Andrew Thompson Apr 13 '17 at 15:36

0 Answers0