Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    5
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    OK, I have to just be brain dead, but I cannot figure out were this null error is. I have looked and the lines and just don't see anything. The error message is:

     Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    	at engineeringSpecificationInterface.EngineeringSpecificationInterface.comboBoxState(EngineeringSpecificationInterface.
    java:783)
    	at engineeringSpecificationInterface.EngineeringSpecificationInterface.access$3(EngineeringSpecificationInterface.java:
    778)
    	at engineeringSpecificationInterface.EngineeringSpecificationInterface$6.itemStateChanged(EngineeringSpecificationInter
    face.java:280)
    	at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
    	at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
    	at javax.swing.JComboBox.contentsChanged(Unknown Source)
    	at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
    	at javax.swing.DefaultComboBoxModel.setSelectedItem(Unknown Source)
    	at javax.swing.JComboBox.setSelectedItem(Unknown Source)
    	at javax.swing.JComboBox.setSelectedIndex(Unknown Source)
    	at javax.swing.plaf.basic.BasicComboPopup$Handler.mouseReleased(Unknown Source)
    	at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at javax.swing.plaf.basic.BasicComboPopup$1.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$200(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

    My full code is:
     package engineeringSpecificationInterface;
     
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
     
    import javax.swing.*;
    import javax.swing.event.*;
     
    import java.text.*;
    import java.util.*;
     
    public class EngineeringSpecificationInterface extends JFrame
    {
    	// Declare variables and objects
    	private static final long serialVersionUID = 1L;
    	private JTabbedPane tabbedPane;
    	private JLabel poolCommentLabel;
    	private JTextField poolLengthText, poolWidthText, poolDepthText, poolVolumeText; 
    	private JLabel tubCommentLabel;
    	private JRadioButton roundButton, ovalButton;
    	private JTextField tubWidthText, tubLengthText, tubDepthText, tubVolumeText; 
    	private JTextField tempText, resultText;
    	private JComboBox comboBox;
    	private JLabel resultLabel;
    	private JTextField milMeterText, meterText, yardText, feetText, inchesText;	
    	private JTextField companyText;
    	private JTextArea customerMessage, customerText;
    	private JTextArea contractorMessage, contractorText;
     
    	// Constructor
    	public EngineeringSpecificationInterface()
    	{
    		// Methods to create GUI
    		MainFrame();
    		PoolTab();
    		HotTubTab();
    		TempCalcTab();
    		LengthCalcTab();
    		GeneralTab();
    		OptionTab();
    		CustomerTab();
    		ContractorTab();
    	}// End constructor
    //*************************************************************************************************************	
    	// Create and format frame
    	private void MainFrame(){
    		this.tabbedPane = new JTabbedPane();
    		this.setTitle("CIS355A Course Project");
    		this.setSize(400, 375);
    		this.add(BorderLayout.CENTER, this.tabbedPane);
    		this.setLocationRelativeTo(null);
    		this.setResizable(false);
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}// End MainFrame method
    //*************************************************************************************************************	
    	// Create and format Pool Tab
    	public void PoolTab(){
     
    		// Format panel
    		JPanel poolPanel = new JPanel();
    		poolPanel.setLayout(null);
    		this.tabbedPane.add("Pool", poolPanel);
     
    		//Create, format and add components to panel
    		JLabel lengthLabel = new JLabel("Enter the pool's length (ft):");
    		lengthLabel.setSize(150, 20);
    		lengthLabel.setLocation(15, 20);
    		poolPanel.add(lengthLabel);
    		poolLengthText = new JTextField();
    		poolLengthText.setSize(125, 20);
    		poolLengthText.setLocation(175, 20);
    		poolPanel.add(poolLengthText);
    		//******************************************************************
    		JLabel widthLabel = new JLabel("Enter the pool's width (ft):");
    		widthLabel.setSize(150, 20);
    		widthLabel.setLocation(15, 55);
    		poolPanel.add(widthLabel);
    		poolWidthText = new JTextField();
    		poolWidthText.setSize(125, 20);
    		poolWidthText.setLocation(175, 55);
    		poolPanel.add(poolWidthText);
    		//******************************************************************
    		JLabel depthLabel = new JLabel("Enter the pool's depth (ft):");
    		depthLabel.setSize(150, 20);
    		depthLabel.setLocation(15, 90);
    		poolPanel.add(depthLabel);
    		poolDepthText = new JTextField();
    		poolDepthText.setSize(125, 20);
    		poolDepthText.setLocation(175, 90);
    		poolPanel.add(poolDepthText);
    		//******************************************************************
    		JButton calculateButton = new JButton("Calculate Volume");
    		calculateButton.setSize(150, 25);
    		calculateButton.setLocation(15, 125);
    		poolPanel.add(calculateButton);
    		calculateButton.setMnemonic('C');
    		calculateButton.addActionListener(new ActionListener(){ 
    		public void actionPerformed(ActionEvent e){ 
    				calculatePoolVolume(); 
    			}
    			}); 
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(100, 25);
    		exitButton.setLocation(170, 125);
    		poolPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    			}
    			}); 
    		//******************************************************************
    		JLabel volumeLabel = new JLabel("The pool's volume is (ft^3):");
    		volumeLabel.setSize(155, 20);
    		volumeLabel.setLocation(15, 175);
    		poolPanel.add(volumeLabel);
    		poolVolumeText = new JTextField();
    		poolVolumeText.setSize(125, 20);
    		poolVolumeText.setLocation(175, 175);
    		poolVolumeText.setEditable(false);
    		poolVolumeText.setBackground(new Color(238,238,238));
    		poolPanel.add(poolVolumeText);
    		//******************************************************************
    		poolCommentLabel = new JLabel();
    		poolCommentLabel.setSize(200, 20);
    		poolCommentLabel.setLocation(15, 215);
    		poolPanel.add(poolCommentLabel);
    	}// End PoolTab method
    //*************************************************************************************************************	
    	//Create and format Hot Tub Tab
    	private void HotTubTab(){
     
    		// Format panel	
    		JPanel hotTubPanel = new JPanel();
    		hotTubPanel.setLayout(null);
    		this.tabbedPane.add("Hot Tubs", hotTubPanel);
     
    		//Create, format and add components to panel
    		roundButton = new JRadioButton();
    		roundButton.setSelected(true);
    		roundButton.setText("Round Tub");
    		roundButton.setSize(85, 20);
    		roundButton.setLocation(45, 5);
    		roundButton.addChangeListener(new ChangeListener(){ 
    			public void stateChanged(ChangeEvent arg0){ 
    				roundButtonState(); 
    			}
    			});
    		hotTubPanel.add(roundButton);
    		//******************************************************************
    		ovalButton = new JRadioButton();
    		ovalButton.setText("Oval Tub");
    		ovalButton.setSize(85, 20);
    		ovalButton.setLocation(165, 5);
    		hotTubPanel.add(ovalButton);
     
    		// Group radio buttons
    		ButtonGroup group = new ButtonGroup();
    		group.add(roundButton);
    		group.add(ovalButton);
    		//******************************************************************
    		JLabel lengthLabel = new JLabel("Enter the tub's length (ft):");
    		lengthLabel.setSize(150, 20);
    		lengthLabel.setLocation(15, 30);
    		hotTubPanel.add(lengthLabel);
    		tubLengthText = new JTextField();
    		tubLengthText.setSize(120, 20);
    		tubLengthText.setLocation(185, 30);
    		hotTubPanel.add(tubLengthText);
    		//******************************************************************
    		JLabel widthLabel = new JLabel("Enter the tub's width (ft):");
    		widthLabel.setSize(150, 20);
    		widthLabel.setLocation(15, 60);
    		hotTubPanel.add(widthLabel);
    		tubWidthText = new JTextField();
    		tubWidthText.setSize(120, 20);
    		tubWidthText.setLocation(185, 60);
    		tubWidthText.setEditable(false);
    		hotTubPanel.add(tubWidthText);
    		//******************************************************************
    		JLabel depthLabel = new JLabel("Enter the tub's depth (ft):");
    		depthLabel.setSize(150, 20);
    		depthLabel.setLocation(15, 95);
    		hotTubPanel.add(depthLabel);
    		tubDepthText = new JTextField();
    		tubDepthText.setSize(120, 20);
    		tubDepthText.setLocation(185, 95);
    		hotTubPanel.add(tubDepthText);
    		//******************************************************************
    		JButton calculateButton = new JButton("Calculate Volume");
    		calculateButton.setSize(150, 25);
    		calculateButton.setLocation(15, 130);
    		hotTubPanel.add(calculateButton);
    		calculateButton.setMnemonic('C');
    		calculateButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e) { 
    				calculateTubVolume(); 
    				}
    			});
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(100, 25);
    		exitButton.setLocation(170, 130);
    		hotTubPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    				}
    			});
    		//******************************************************************
    		JLabel volumeLabel = new JLabel("The tub's volume is (ft^3):");
    		volumeLabel.setSize(155, 20);
    		volumeLabel.setLocation(15, 180);
    		hotTubPanel.add(volumeLabel);
    		tubVolumeText = new JTextField();
    		tubVolumeText.setSize(120, 20);
    		tubVolumeText.setLocation(185, 180);
    		tubVolumeText.setEditable(false);
    		tubVolumeText.setBackground(new Color(238,238,238));
    		hotTubPanel.add(tubVolumeText);	
    		//******************************************************************
    		tubCommentLabel = new JLabel();
    		tubCommentLabel.setSize(200, 20);
    		tubCommentLabel.setLocation(15, 215);
    		hotTubPanel.add(tubCommentLabel);
    	}// End HotTub method
    //*************************************************************************************************************	
    	// Create and format Temperature Calculator Tab 
    	private void TempCalcTab(){
     
    		// Format panel
    		JPanel tempCalcPanel = new JPanel();
    		tempCalcPanel.setLayout(null);
    		this.tabbedPane.addTab("Temp Calc", tempCalcPanel);
     
    		//Create, format and add components to panel
    		JLabel tempLabel = new JLabel("Enter Temperature:");
    		tempLabel.setSize(115, 20);
    		tempLabel.setLocation(10, 40);
    		tempCalcPanel.add(tempLabel);
    		tempText = new JTextField();
    		tempText.setSize(120, 20);
    		tempText.setLocation(140, 40);
    		tempText.setText("0");
    		tempCalcPanel.add(tempText);
    		//******************************************************************
    		JLabel resultLabel = new JLabel("Result:");
    		resultLabel.setSize(45, 20);
    		resultLabel.setLocation(10, 80);
    		tempCalcPanel.add(resultLabel);
    		resultLabel = new JLabel("F");
    		resultLabel.setSize(15, 20);
    		resultLabel.setLocation(280, 80);
    		tempCalcPanel.add(resultLabel);
    		//******************************************************************
    		resultText = new JTextField();
    		resultText.setSize(120, 20);
    		resultText.setLocation(140, 80);
    		resultText.setEditable(false);
    		resultText.setText("32");
    		tempCalcPanel.add(resultText);
    		//******************************************************************
    		comboBox = new JComboBox(new String[] {"C", "F"});
    		comboBox.setSize(90, 25);
    		comboBox.setLocation(280, 40);
    		comboBox.setEditable(false);
    		comboBox.addItemListener(new ItemListener(){ 
    			public void itemStateChanged(ItemEvent e){ 
    				comboBoxState(); 
    				}
    			});
    		tempCalcPanel.add(comboBox);
    		//******************************************************************
    		JButton convertButton = new JButton("Convert");
    		convertButton.setSize(150, 25);
    		convertButton.setLocation(35, 120);
    		tempCalcPanel.add(convertButton);
    		convertButton.setMnemonic('C');
    		convertButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				convertTemperature(); 
    				}
    			});
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(100, 25);
    		exitButton.setLocation(190, 120);
    		tempCalcPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    				}
    			});
    	}// End TempCalcTab method
    //*************************************************************************************************************		
    	// Create and format Length Calculator Tab
    	private void LengthCalcTab(){
     
    		// Format panel
    		JPanel lengthCalcPanel = new JPanel();
    		lengthCalcPanel.setLayout(null);
    		this.tabbedPane.add("Length Calc", lengthCalcPanel);
     
    		//Create, format and add components to panel
    		JLabel milMeterLabel = new JLabel("Millimeters");
    		milMeterLabel.setSize(65, 20);
    		milMeterLabel.setLocation(15, 25);
    		lengthCalcPanel.add(milMeterLabel);
    		milMeterText = new JTextField();
    		milMeterText.setSize(65, 20);
    		milMeterText.setLocation(15, 45);
    		milMeterText.setEditable(false);
    		lengthCalcPanel.add(milMeterText);
    		//******************************************************************
    		JLabel meterLabel = new JLabel("Meters");
    		meterLabel.setSize(65, 20);
    		meterLabel.setLocation(90, 25);
    		lengthCalcPanel.add(meterLabel);
    		meterText = new JTextField();
    		meterText.setSize(65, 20);
    		meterText.setLocation(90, 45);
    		meterText.setEditable(false);
    		lengthCalcPanel.add(meterText);
    		//******************************************************************
    		JLabel yardLabel = new JLabel("Yards");
    		yardLabel.setSize(65, 20);
    		yardLabel.setLocation(160, 25);
    		lengthCalcPanel.add(yardLabel);
    		yardText = new JTextField();
    		yardText.setSize(65, 20);
    		yardText.setLocation(160, 45);
    		yardText.setEditable(false);
    		lengthCalcPanel.add(yardText);
    		//******************************************************************
    		JLabel feetLabel = new JLabel("Feet");
    		feetLabel.setSize(65, 20);
    		feetLabel.setLocation(230, 25);
    		lengthCalcPanel.add(feetLabel);
    		feetText = new JTextField();
    		feetText.setSize(65, 20);
    		feetText.setLocation(230, 45);
    		lengthCalcPanel.add(feetText);
    		//******************************************************************
    		JLabel inchesLabel = new JLabel("Inches");
    		inchesLabel.setSize(65, 20);
    		inchesLabel.setLocation(300, 25);
    		lengthCalcPanel.add(inchesLabel);
    		inchesText = new JTextField();
    		inchesText.setSize(65, 20);
    		inchesText.setLocation(300, 45);
    		inchesText.setEditable(false);
    		lengthCalcPanel.add(inchesText);
    		//******************************************************************
    		JButton convertButton = new JButton("Convert");
    		convertButton.setSize(150, 25);
    		convertButton.setLocation(35, 120);
    		lengthCalcPanel.add(convertButton);
    		convertButton.setMnemonic('C');
    		convertButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				convertLength(); 
    				}
    			});
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(100, 25);
    		exitButton.setLocation(190, 120);
    		lengthCalcPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    				}
    			});	
    	}// End lengthCalcTab method	
    //*************************************************************************************************************		
    	// Create and format General Tab	
    	private void GeneralTab(){
     
    		// Format panel
    		JPanel generalPanel = new JPanel();
    		generalPanel.setLayout(null);
    		this.tabbedPane.addTab("General", generalPanel);
     
    		//Create, format and add components to panel
    		JLabel dateTodayLabel = new JLabel("Today's Date:");
    		dateTodayLabel.setSize(80, 25);
    		dateTodayLabel.setLocation(45, 40);
    		generalPanel.add(dateTodayLabel);
    		//******************************************************************
    		JLabel dateLabel = new JLabel("mm/dd/yyyy");
    		dateLabel.setSize(80, 25);
    		dateLabel.setLocation(165, 40);
    		generalPanel.add(dateLabel);
    		SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
    		dateLabel.setText(dateFormat.format(new Date()));
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(110, 25);
    		exitButton.setLocation(260, 40);
    		generalPanel.add(exitButton);
    		exitButton.setMnemonic('X');
     
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); }});		
    	}// End GeneralTab method
    //*************************************************************************************************************	
    	//Create and format Option Tab
    	private void OptionTab(){
     
    		// Format panel
    		JPanel optionsPanel = new JPanel();
    		optionsPanel.setLayout(null);
    		this.tabbedPane.addTab("Options", optionsPanel);
     
    		// Create, format and add components to panel
    		JLabel changeCompanyLabel = new JLabel("Change Company Name:");
    		changeCompanyLabel.setSize(150, 25);
    		changeCompanyLabel.setLocation(68, 15);
    		optionsPanel.add(changeCompanyLabel);
    		//******************************************************************
    		companyText = new JTextField();
    		companyText.setSize(200, 20);
    		companyText.setLocation(30, 45);
    		optionsPanel.add(companyText);
    		//******************************************************************
    		JButton newNameButton = new JButton("Set New Name");
    		newNameButton.setSize(130, 25);
    		newNameButton.setLocation(20, 85);
    		optionsPanel.add(newNameButton);
    		newNameButton.setMnemonic('S');
    		newNameButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				replaceName();
    				}
    			});
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(110, 25);
    		exitButton.setLocation(170, 85);
    		optionsPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    				}
    			});
    	}// End OptionsTab method
    //*************************************************************************************************************
    	// Create and format Customer Tab
    	private void CustomerTab(){
     
    		// Format panel
    		JPanel customerPanel = new JPanel();
    		customerPanel.setLayout(null);
    		this.tabbedPane.add("Customers", customerPanel);
     
    		// Create, format and add components to panel
    		customerText = new JTextArea();
    		customerText.setText("Select Add Customer to add customers.\nSelect Refresh to refresh this page.");
    		customerText.setSize(360, 140);
    		customerText.setLocation(10, 10);
    		customerText.setEditable(false);
    		customerText.setBorder(BorderFactory.createEtchedBorder());
    		customerPanel.add(customerText);
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(70, 25);
    		exitButton.setLocation(10, 160);
    		customerPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    				}
    			});
    		//******************************************************************
    		JButton addCustomerButton = new JButton("Add Customer");
    		addCustomerButton.setSize(125,25);
    		addCustomerButton.setLocation(90, 160);
    		customerPanel.add(addCustomerButton);
    		addCustomerButton.setMnemonic('A');
    		addCustomerButton.addActionListener(new ActionListener(){ 
    		public void actionPerformed(ActionEvent e){ 
    			addCustomer(); 
    			}
    		});
    		//******************************************************************
    		JButton refreshButton = new JButton("Refresh");
    		refreshButton.setSize(95, 25);
    		refreshButton.setLocation(220, 160);
    		customerPanel.add(refreshButton);
    		refreshButton.setMnemonic('R');
    		refreshButton.addActionListener(new ActionListener(){  
    		public void actionPerformed(ActionEvent e){ 
    		refreshCustomer(); 
    		}
    		});
    		//******************************************************************
    		customerMessage = new JTextArea();
    		customerMessage.setText("File customer.txt does not exist yet.\nWill be created when you add a customer!");
    		customerMessage.setSize(360, 45);
    		customerMessage.setLocation(10, 190);
    		customerMessage.setEditable(false);
    		customerMessage.setBorder(BorderFactory.createEtchedBorder());
    		customerPanel.add(customerMessage);		
    	}// End CustomerTab method
    //*************************************************************************************************************	
    	// Create and format Contractor Tab
    	private void ContractorTab(){
     
    		// Format panel
    		JPanel contractorPanel = new JPanel();
    		contractorPanel.setLayout(null);
    		this.tabbedPane.add("Contractors", contractorPanel);
     
    		// Create, format and add components to panel
    		contractorText = new JTextArea();
    		contractorText.setText("Select Add Contractor to add contractors. \nSelect Refresh to refresh this page.");
    		contractorText.setSize(360, 140);
    		contractorText.setLocation(10, 10);
    		contractorText.setEditable(false);
    		contractorText.setBorder(BorderFactory.createEtchedBorder());
    		contractorPanel.add(contractorText);
    		//******************************************************************
    		JButton exitButton = new JButton("Exit");
    		exitButton.setSize(70, 25);
    		exitButton.setLocation(10, 160);
    		contractorPanel.add(exitButton);
    		exitButton.setMnemonic('X');
    		exitButton.addActionListener(new ActionListener(){ 
    			public void actionPerformed(ActionEvent e){ 
    				closeProgram(); 
    				}
    			});
    		//******************************************************************
    		JButton addContractorButton = new JButton("Add Contractor");
    		addContractorButton.setSize(125,25);
    		addContractorButton.setLocation(90, 160);
    		contractorPanel.add(addContractorButton);
    		addContractorButton.setMnemonic('A');
    		addContractorButton.addActionListener(new ActionListener(){ 
    		public void actionPerformed(ActionEvent e){ 
    			addContractor();
    			}
    		});
    		//******************************************************************
    		JButton refreshButton = new JButton("Refresh");
    		refreshButton.setSize(95, 25);
    		refreshButton.setLocation(220, 160);
    		contractorPanel.add(refreshButton);
    		refreshButton.setMnemonic('R');
    		refreshButton.addActionListener(new ActionListener(){ 
    		public void actionPerformed(ActionEvent e){ 
    			refreshContractor();
    		}	
    		});
    		//******************************************************************
    		contractorMessage = new JTextArea();
    		contractorMessage.setText("File contract.txt does not exist yet.\nWill be created when you add contractor!");
    		contractorMessage.setSize(360, 45);
    		contractorMessage.setLocation(10, 190);
    		contractorMessage.setEditable(false);
    		contractorMessage.setBorder(BorderFactory.createEtchedBorder());
    		contractorPanel.add(contractorMessage);		
    	}// End ContractorTab method
    //*************************************************************************************************************		
    	// Method to close the program from all tabs
    	public void closeProgram()
    	{
    		this.setVisible(false);
    	}
    //*************************************************************************************************************	ode
    //-------------------------------------------------------------------------------------------------------------	
    //*****************************METHODS FOR OPERATIONS PERFORMED IN TABS****************************************
    // Formatting and Calculating Pool Volume
    private void calculatePoolVolume(){
     
    		// Declare variables
    		DecimalFormat decimalFormat = new DecimalFormat("###.##");	
    		double length = 0.0, width = 0.0, depth = 0.0;
            String error = "";
     
            // Format text boxes
            poolCommentLabel.setText("");
            poolLengthText.setBackground(Color.WHITE);
            poolWidthText.setBackground(Color.WHITE);
            poolDepthText.setBackground(Color.WHITE);
     
            // Validating fields have input
            if (poolLengthText.getText().trim().length() < 1){
            	poolLengthText.setBackground(Color.YELLOW);
                error = "Please fill out all the fields";
            }
     
            if (poolWidthText.getText().trim().length() < 1){
            	poolWidthText.setBackground(Color.YELLOW);
                error = "Please fill out all the fields";
            }
     
            if (poolDepthText.getText().trim().length() < 1){
            	poolDepthText.setBackground(Color.YELLOW);
                error = "Please fill out all the fields";
            }
     
            if (error.length() > 0) {
                poolCommentLabel.setText(error);
                return;
            }
     
            // Validating proper input
            try {
                length = Double.parseDouble(poolLengthText.getText());
            }
            catch (Exception ex){
            	poolLengthText.setBackground(Color.YELLOW);
                error = "Please enter valid numbers";
            }
     
            try{
                width = Double.parseDouble(poolWidthText.getText());
            } 
            catch (Exception ex){
            	poolWidthText.setBackground(Color.YELLOW);
                error = "Please enter valid numbers";
            }
     
            try{
                depth = Double.parseDouble(poolDepthText.getText());
            } 
            catch (Exception ex){
            	poolDepthText.setBackground(Color.YELLOW);
                error = "Please enter valid numbers";
            }
     
            if (error.length() > 0){
                poolCommentLabel.setText(error);
                return;
            }
     
            // Calculating volume and formatting results
            double volume = width * length * depth;
            poolVolumeText.setText(decimalFormat.format(volume));
     
            // Writing data to pool.txt  
            try {
    			String value = poolVolumeText.getText();
    			File file = new File("pool.txt");
    			FileWriter fstream = new FileWriter(file, true);
    			BufferedWriter out = new BufferedWriter(fstream);
    			out.write("Length= " + length + ", Width= " + width
    					+ ", Depth= " + depth
    					+ " Volume of Swimming Pool is " + value);
    			out.newLine();
    			out.close();
    		} catch (Exception e) {
    		}
    	}// End calculatePoolVolume method	
    //-------------------------------------------------------------------------------------------------------------	
    // Calculating and Formatting Hot Tub Volume	
     
    // Formatting text field depending on which radio button is selected 
    private void roundButtonState(){
    		if(roundButton.isSelected()){
    			tubWidthText.setEditable(false);
    		}
    		else{
    			tubWidthText.setEditable(true);
    		}
    	}// End roundButtonState method
     
    	// Formatting and calculating Hot Tub Volume
    	private void calculateTubVolume(){
    			// Declare variables
    		DecimalFormat decimalFormat = new DecimalFormat("###.##");
    		double length = 0.0, width = 0.0, depth = 0.0;
            String error = "";
     
            // Formatting text boxes
            tubCommentLabel.setText("");
            tubLengthText.setBackground(Color.WHITE);
            tubWidthText.setBackground(Color.WHITE);
            tubDepthText.setBackground(Color.WHITE);
     
            // Formating for round button selected
    		if(roundButton.isSelected()){
    			tubWidthText.setText(tubLengthText.getText());
    		}
     
            // Validating fields have input
            if (tubLengthText.getText().trim().length() < 1){
            	tubLengthText.setBackground(Color.YELLOW);
                error = "Please fill out all the fields";
            }
     
            if (tubWidthText.getText().trim().length() < 1){
            	tubWidthText.setBackground(Color.YELLOW);
                error = "Please fill out all the fields";
            }
     
            if (tubDepthText.getText().trim().length() < 1){
            	tubDepthText.setBackground(Color.YELLOW);
                error = "Please fill out all the fields";
            }
     
            if (error.length() > 0){
            	tubCommentLabel.setText(error);
                return;
            }
     
            // Validating proper input
            try{
                length = Double.parseDouble(tubLengthText.getText());
            } 
            catch (Exception e){
            	tubLengthText.setBackground(Color.YELLOW);
                error = "Please enter valid numbers";
            }
     
            try{
                width = Double.parseDouble(tubWidthText.getText());
            } 
            catch (Exception e) 
            {
            	tubWidthText.setBackground(Color.YELLOW);
                error = "Please enter valid numbers";
            }
     
            try{
                depth = Double.parseDouble(tubDepthText.getText());
            } 
            catch (Exception e){
            	tubDepthText.setBackground(Color.YELLOW);
                error = "Please enter valid numbers";
            }
     
            if (error.length() > 0){
            	tubCommentLabel.setText(error);
                return;
            }
     
            // Calculating volume and formatting results
            double volume =  (Math.PI * ((length/2) * (width/2))) * depth;
     
            tubVolumeText.setText(decimalFormat.format(volume));
     
            // Writing data to hot_tub.txt  
            try {
    			String value = tubVolumeText.getText();
    			File file = new File("hot_tub.txt");
    			FileWriter fstream = new FileWriter(file, true);
    			BufferedWriter out = new BufferedWriter(fstream);
    			out.write("Length= " + length + ", Width= " + width
    					+ ", Depth= " + depth
    					+ " Volume of Hot Tub is " + value);
    			out.newLine();
    			out.close();
    		} catch (Exception e) {
    		}
    	}// End tubCalculate
    //-------------------------------------------------------------------------------------------------------------		
    // Calculating and Formatting Temperature Calculator
     
    	// Determining the result label
    	private void comboBoxState(){
    		if(comboBox.getSelectedItem().toString().equals("C")){
    			resultLabel.setText("F");
    		}
    		else{
    			resultLabel.setText("C");
    		}
    	}// End comboBoxState method
     
    	// Formatting and calculating temperature conversions 
    	private void convertTemperature(){
     
    		// Declare variables
    		double temperature = 0.0;
            double result = 0.0;
     
            // Validating input
    		if(tempText.getText().length() < 1){
    			tempText.setText("0");
    		}
     
    		try{
            	temperature = Double.parseDouble(tempText.getText());
            } 
     
            catch(Exception ex){
            	temperature = 0.0;
            }
     
            // Converting to celsius or fahrenheit 
            if(comboBox.getSelectedItem().toString().equals("C")){
                result = (temperature  *  9/5) + 32;
            }
     
            else{
            	result = (temperature  -  32)  *  5/9;
            }
     
            // Format and display results
            DecimalFormat decimalFormat = new DecimalFormat("##.##");
            resultText.setText(decimalFormat.format(result));
    	}// End convert temperature method
    //-------------------------------------------------------------------------------------------------------------		
    	// Calculating and Formatting Hot Tub Volume	
    	private void convertLength(){
     
    		// Declare variables
    		double feet = 0.0;
            double milliMeter = 0.0;
            double meter = 0.0;
            double yards = 0.0;
            double inches = 0.0;
     
            // Validating input
            try{
                feet = Double.parseDouble(feetText.getText());
            } 
            catch (Exception ex){
                feet = 0;
                feetText.setText("0");
            }
     
            // Converting length
            milliMeter = feet * 304.8;
            meter = feet * 0.3048;
            yards = feet * 0.3333;
            inches = feet * 12;
     
            // Formatting and display results
            DecimalFormat decimalFormat = new DecimalFormat("####.###");
            milMeterText.setText(decimalFormat.format(milliMeter));
            meterText.setText(decimalFormat.format(meter));
            yardText.setText(decimalFormat.format(yards));
            inchesText.setText(decimalFormat.format(inches));
    	}// End convertLength method
    //-------------------------------------------------------------------------------------------------------------		
    	// Method to replace company name in option tab
    	private void replaceName()
    	{
    		this.setTitle(this.companyText.getText());
    	} 
    //-------------------------------------------------------------------------------------------------------------	
    // Formatting and defining Customer Functions  	
     
    	// Method to add customer
    	private void addCustomer(){
    		AddCustomer dialog = new AddCustomer(this);
    		dialog.setVisible(true);
    	}
     
    	// Method to check if database file exists
    	private void refreshCustomer(){
    		File file = new File("customer.txt");
     
            if (!file.exists()){
            	customerMessage.setText("File customer.txt does not exist yet.\nWill be created when you add customer!");
                return;
            }
            else{
            customerMessage.setText("File customer.txt exists and can be read from!");}
            String string = FileManager.readFromFile("customer.txt");
            customerText.setText(string);
    	}	
    //-------------------------------------------------------------------------------------------------------------
    // Formatting and defining Contractor Functions  	
     
    	// Method to add contractor
    	private void addContractor(){
    		AddContractor dialog = new AddContractor(this);
    		dialog.setVisible(true);
    	}
     
    	// Method to check if database file exists
    	private void refreshContractor(){
    		File file = new File("contractor.txt");
     
            if (!file.exists()){
            	contractorMessage.setText("File contractor.txt does not exist yet.\nWill be created when you add contractor!");
                return;
            }
            else{
            contractorMessage.setText("File contractor.txt exists and can be read from!");}
            String string = FileManager.readFromFile("contractor.txt");
            contractorText.setText(string);
    	}
    //-------------------------------------------------------------------------------------------------------------
    //*************************************************************************************************************	
     
    	// Main Method
    	public static void main(String[] args)
    	{
    		// start the program by showing the main frame
    		EngineeringSpecificationInterface main = new EngineeringSpecificationInterface();
    		main.setVisible(true);
    	}
    }// End class

    What the heck am I missing? I know it has to be something simple.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at engineeringSpecificationInterface.EngineeringSpeci ficationInterface.comboBoxState(EngineeringSpecifi cationInterface.
    java:783)
    Look at the variables on line 783 and see which one has a null value. If you can't tell by looking, add a println() statement just before line 783 that prints out the values of all the variables on line 783 so you can see which one has the null value. Then backtrack in the code to see why it is null.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  2. Replies: 6
    Last Post: March 21st, 2013, 06:43 AM
  3. Replies: 2
    Last Post: November 24th, 2012, 09:18 AM
  4. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM
  5. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 10:46 PM

Tags for this Thread