Results 1 to 2 of 2
  1. #1
    Embercloud is offline Member
    Join Date
    Dec 2010
    Rep Power

    Default Combo box trouble turning into a boxing match with java

    So I try to create a object and put it into a combobox. The same code works when putting an object into a defaultlistmodel.

    in my main constructor:

    Java Code:
      public static JComboBox cb;
    JComboBox cb = new JComboBox();
    public static void insertperson(JComboBox cb, Person person) {
              insertperson(cb, Personlista.person1);
    	  insertperson(cb, Personlista.person2);
    	  insertperson(cb, Personlista.person3);
    	  insertperson(cb, Personlista.person4);
    in a separate popupwindow:

    Java Code:
    public class nyperson extends JPanel{
    	private static final long serialVersionUID = 1L;
    	public void rensa(JTextField a, JTextField b, JTextField c ) { 
    	public void save (JTextField a, JTextField b, JTextField c){
    		String fornamn = a.getText();
    		String efternamn = b.getText();
    		String phonenr = c.getText();
    		Person person = new Person (fornamn, efternamn, phonenr);
    		Manager.insertperson(Manager.cb, person);
    		JPanel jpn = new JPanel(new GridLayout (4, 4));
    	    final JTextField fornamn = new JTextField(10);
    		final JTextField efternamn = new JTextField(10);
    		final JTextField phonenr = new JTextField(10);
    		JLabel bokensnamn = new JLabel ("Förnamn:");
    		JLabel forfattarensnamn = new JLabel ("Efternamn: ");
    		JLabel aret = new JLabel ("Telefonnummer: ");
    		JButton spara = new JButton ("Spara");
    		JButton rensa = new JButton ("Rensa");
    		jpn.add(bokensnamn, ("1"));
    		jpn.add(fornamn, ("1"));
    		jpn.add(forfattarensnamn, ("2"));
    		jpn.add(efternamn, ("2"));
    		jpn.add(aret, ("3"));
    		jpn.add(phonenr, ("3"));
    		jpn.add(rensa, ("4"));
    		jpn.add(spara, ("4"));
    		spara.addActionListener(new ActionListener() {
    		      public void actionPerformed(ActionEvent e) {
    		    	  save(fornamn, efternamn, phonenr);
    		rensa.addActionListener(new ActionListener() {
    		      public void actionPerformed(ActionEvent e) {
    		    	  rensa(fornamn, efternamn, phonenr);
    When I run this code I get a NullPointerException but I can't figure out why.
    Last edited by Embercloud; 01-05-2011 at 04:24 AM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power


    Java Code:
     public static JComboBox cb;
    JComboBox cb = new JComboBox();
    The second line is standing in the constructor? Remove the first JComboBox in the second line, otherwise you create a new local variable!
    But with this little piece of code and without posting in which line its hard to say why you get there a NPE.

Similar Threads

  1. dynamically populate the city combo box based on the values of state combo +ajax+jsp
    By sandy1000 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-29-2010, 10:00 AM
  2. Replies: 3
    Last Post: 08-11-2009, 12:18 AM
  3. Need help getting java drawing match to image.
    By kiduut in forum New To Java
    Replies: 9
    Last Post: 12-28-2008, 01:55 PM
  4. Java Developer - Need Job - This is Perfect match
    By ravisrivastava2003 in forum Java Software
    Replies: 0
    Last Post: 12-10-2008, 07:35 PM
  5. creation of one combo box form another combo box
    By er.tyagigaurav in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-09-2008, 03:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts