0
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at my.Posterordering.PosterorderingUI.combostyleActionPerformed(PosterorderingUI.java:394)
at my.Posterordering.PosterorderingUI.access$500(PosterorderingUI.java:17)
at my.Posterordering.PosterorderingUI$6.actionPerformed(PosterorderingUI.java:201)
at javax.swing.JComboBox.fireActionEvent(JComboBox.java:1258)
at javax.swing.JComboBox.setSelectedItem(JComboBox.java:586)
at javax.swing.JComboBox.setSelectedIndex(JComboBox.java:622)
at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(BasicComboPopup.java:834)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:290)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(BasicComboPopup.java:498)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Having issues with my code when I try to run it, this is the code that I have:

package my.Posterordering;

/**
 *
 * @author 100103562
 */
import javax.swing.*;
import javax.swing.JButton;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class PosterorderingUI extends javax.swing.JFrame {
/**
 * Creates new form PosterorderingUI
 */

Double total = null;
    Double size = null;
    Double quantity = null;
    Double colour = null;
    Double style = null;
    int postage = 10;



private void BtnHelpActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    JDialogExample jDialogExample = new JDialogExample();

}                                       

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
   dispose();
}                                        

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
}                                        

private void BtnHelpMouseClicked(java.awt.event.MouseEvent evt) {                                     
    // TODO add your handling code here:
    PosterorderingUI newFrame = new PosterorderingUI();
    newFrame.setVisible(true);
    jLabel15.setText("test");
}                                    

private void comboSizeActionPerformed(java.awt.event.ActionEvent evt) {                                          
    // TODO add your handling code here:


     if (comboSize.getSelectedItem().equals("Large")){
lblpstprice.setText(String.valueOf(10.00));
int size = 10;
lblTotal.setText(String.valueOf(size + postage));
     }

else if (comboSize.getSelectedItem().equals("Small")){
           lblpstprice.setText(String.valueOf(3.00));

           int size = 3;
           lblTotal.setText(String.valueOf(size + postage));
}
     else if (comboSize.getSelectedItem().equals("Medium")){
           lblpstprice.setText(String.valueOf(6.00));
           int size = 6;
           lblTotal.setText(String.valueOf(size + postage));
}
       else {
           lblpstprice.setText(String.valueOf("Please select a poster size"));
           lblTotal.setText(String.valueOf("Error Occured"));
}
    }                                         

private void combostyleActionPerformed(java.awt.event.ActionEvent evt) {                                           
    // TODO add your handling code here:
    if (combostyle.getSelectedItem().equals("Laminated")){
        lblstyleprice.setText(String.valueOf(5.00));
        int style = 5;
        lblTotal.setText(String.valueOf(size + style + postage));
}

else if (combostyle.getSelectedItem().equals("Glossy")){
           lblstyleprice.setText(String.valueOf(10.00));
           int style = 5;
           lblTotal.setText(String.valueOf(size + style + postage));
}
else if (combostyle.getSelectedItem().equals("Uncoated")){
           lblstyleprice.setText(String.valueOf(0.00));
           int style = 0;
           lblTotal.setText(String.valueOf(size + style + postage));
}

else {
           lblstyleprice.setText(String.valueOf("Please select a poster style"));
}

}                                          

private void comboclrActionPerformed(java.awt.event.ActionEvent evt)     {                                         
    // TODO add your handling code here:
    if (comboclr.getSelectedItem().equals("Black")){
    lblcolprice.setText(String.valueOf(2.00));
    int colour = 2;
    lblTotal.setText(String.valueOf(size + style + colour + postage));
    }

    else if (comboclr.getSelectedItem().equals("Red")){
    lblcolprice.setText(String.valueOf(3.00));
    int colour = 3;
    lblTotal.setText(String.valueOf(size + style + colour + postage));
    }

    else if (comboclr.getSelectedItem().equals("Orange")){
    lblcolprice.setText(String.valueOf(3.00));
    int colour = 3;
    lblTotal.setText(String.valueOf(size + style + colour + postage));
    }

    else if (comboclr.getSelectedItem().equals("Blue")){
    lblcolprice.setText(String.valueOf(3.00));
    lblTotal.setText(String.valueOf(size + style + colour + postage));
    int colour = 3;
    }

    else if (comboclr.getSelectedItem().equals("Yellow")){
    lblcolprice.setText(String.valueOf(3.00));
    int colour = 3;
    lblTotal.setText(String.valueOf(size + style + colour + postage));
    }

else {
           lblcolprice.setText(String.valueOf("Please select a color"));
           lblTotal.setText(String.valueOf("An error has occured"));
}    

if (combostyle.getSelectedItem().equals(" ") || (comboSize.getSelectedItem().equals(" ")) || (comboclr.getSelectedItem().equals(" "))){
lblqtot.setText(String.valueOf("Please complete the form"));           
}

else if (comboquant.getSelectedItem().equals(1)){
int number = Integer.parseInt(lblTotal.getText());
int price = 1;
lblqtot.setText(String.valueOf(number * price));
lblTotal.setText(String.valueOf(size + style + colour + postage));
           }

else if (comboquant.getSelectedItem().equals(2)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 1;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

 else if (comboquant.getSelectedItem().equals(3)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 2;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(4)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 3;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(5)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 4;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(6)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 6;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(7)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 7;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(8)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 8;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(9)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 9;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(10)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 10;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(11)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 11;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(12)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 12;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(13)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 13;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));
           }

else if (comboquant.getSelectedItem().equals(14)){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 15;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));

               }

else if (comboquant.getSelectedItem().equals("15")){
int totals = Integer.parseInt(lblTotal.getText());
int quantity = 15;
lblTotal.setText(String.valueOf(size + style + colour + postage));
lblqtot.setText(String.valueOf(totals * quantity));

               }



}                      

I hope that the code is easy enough to understand (it's slightly messy atm sadly!) I am having this error when I select anything on the poster style combobox. The Poster Size box works fine, so I am a little stumped!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Phil Marsh
  • 53
  • 6
  • You need to slim down your code, most people will not read through all of this. Figure out which line the error is happening on (looks like 394) and post relevant code from there. (We can't see line numbers from what you posted). – Avantol13 Jun 01 '15 at 19:47
  • My apologies, I will do this shortly once I get my laptop back online (that has the code) - My apologies for the inconvenience! – Phil Marsh Jun 01 '15 at 20:43

2 Answers2

1

Your Double size is always null. You dont set it in the combostyleActionPerformed() method but try to use in sum

StanislavL
  • 56,971
  • 9
  • 68
  • 98
0

Its hard to tell given this large block of code. If I had to guess it is because of these:

else if (comboquant.getSelectedItem().equals(1)){
int number = Integer.parseInt(lblTotal.getText());
int price = 1;
lblqtot.setText(String.valueOf(number * price));
lblTotal.setText(String.valueOf(size + style + colour + postage));
           }

I think you need to have it start with 0 instead of 1, which would cause a Null Pointer Exception: else if (comboquant.getSelectedItem().equals(0)){

Kevin Mee
  • 539
  • 3
  • 14