title: Getting selected Items from Jlist
body: <p>I have seen many posts &amp; tried different ways to solve this problem but still I dont get my list of selected items. Here's the code which I use. </p>
  
  <pre><code>public List&lt;String&gt; getSelectedDeviceList()
      {
          return list;
      }
      /**
       * Create the frame.
       */
      public JLogicDesign(Frame frame, List&lt;String&gt; listDevices) {
  
          super();
          setTitle("Device Names");
  
          setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          setBounds(100, 100, 331, 316);
          contentPane = new JPanel();
          contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
          setContentPane(contentPane);
  
          jlistModel = new DefaultListModel(); 
          for(String s: listDevices)
          {
              jlistModel.addElement(s);
          }
  
          final JList jlist = new JList(jlistModel);
          jlist.setVisibleRowCount(5);
          JScrollPane scrollPane = new JScrollPane();
          scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  
  
          btnOk = new JButton("OK");      
          btnOk.addActionListener(new ActionListener()
          {
              public void actionPerformed(ActionEvent evt)
              {                   
  
                      list = new ArrayList&lt;String&gt;();
                      Object[] values = jlist.getSelectedValues();
                      for(Object o: values)
                      {
                          list.add(o.toString());
                      }               
                  dispose();
              }
          });
  </code></pre>
  
  <p>The JList is being properly populated. When I try to get the selected Items, I get a NPE.</p>
  
  <p>This is another class where I'm calling the above class</p>
  
  <pre><code>JLogicDesign jld = new JLogicDesign(f,listOfDevices);           
  
              devices = new ArrayList&lt;String&gt;();
              devices = jld.getSelectedDeviceList();
  </code></pre>
  
  <p>Thanks in advance !!</p>