试图让Image导入但我得到一个错误

时间:2017-04-13 15:20:05

标签: java swing nullpointerexception joptionpane

我正在尝试将图像添加到我的JOptionPane中,并且我一直在拼凑一些东西以查看它是否可行但我得到的是NullPointerException

这是我的代码:

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]);

0 个答案:

没有答案