473,544 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

help with Exception in thread "main" java.lang.NullP ointerException

1 New Member
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro
run:
Exception in thread "main" java.lang.NullP ointerException
at java.awt.Contai ner.addImpl(Con tainer.java:104 1)
at java.awt.Contai ner.add(Contain er.java:365)
at orderingsystem. OrderingSystem. <init>(Ordering System.java:261 )
at orderingsystem. OrderingSystem. main(OrderingSy stem.java:361)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
thanks for any help


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package orderingsystem;

import javax.swing.*;
import java.lang.Strin g;
import java.awt.*;
import java.awt.event. *;
import java.text.Numbe rFormat;
import java.util.Local e;


/**
*
* @author Scott.Emberson1 2
*/
public class OrderingSystem extends JFrame {
//widgets

//Genral widegets
JPanel panelWidget;
Toolkit toolkit;
JButton buttonWidget;
//Jlabels
JLabel PizzaShackWidge t;
JLabel priceLabel;
JLabel subtotalLabel;
JLabel totalLabel;
JLabel numberLabel1;
JLabel numberLabel2;
JLabel numberLabel3;
JLabel numberLabel4;
JLabel numberLabel5;
JLabel numberLabel6;
JLabel numberLabel7;
JLabel numberLabel8;
JLabel numberLabel9;
JLabel numberLabel10;

//JCombox
JComboBox DrinksComboBoxW idget;
JComboBox DrinksCombo1;
JComboBox PizzaCombo1;
JComboBox PizzaBaseCombo1 ;
JComboBox IceCombo1;

JComboBox DrinksCombo2;
JComboBox PizzaCombo2;
JComboBox PizzaBaseCombo2 ;
JComboBox IceCombo2;

JComboBox DrinksCombo3;
JComboBox PizzaCombo3;
JComboBox PizzaBaseCombo3 ;
JComboBox IceCombo3;

JComboBox DrinksCombo4;
JComboBox PizzaCombo4;
JComboBox PizzaBaseCombo4 ;
JComboBox IceCombo4;

JComboBox DrinksCombo5;
JComboBox PizzaCombo5;
JComboBox PizzaBaseCombo5 ;
JComboBox IceCombo5;

JComboBox DrinksCombo6;
JComboBox PizzaCombo6;
JComboBox PizzaBaseCombo6 ;
JComboBox IceCombo6;

JComboBox DrinksCombo7;
JComboBox PizzaCombo7;
JComboBox PizzaBaseCombo7 ;
JComboBox IceCombo7;

JComboBox DrinksCombo8;
JComboBox PizzaCombo8;
JComboBox PizzaBaseCombo8 ;
JComboBox IceCombo8;

JComboBox DrinksCombo9;
JComboBox PizzaCombo9;
JComboBox PizzaBaseCombo9 ;
JComboBox IceCombo9;

JComboBox DrinksCombo10;
JComboBox PizzaCombo10;
JComboBox PizzaBaseCombo1 0;
JComboBox IceCombo10;


//JTextField
JTextField NameWidget;
JTextField NumbweOfPeopleW idget;
JTextField TimeSeatedWidge t;
JTextField quantityTextFie ld;


//Close of Widgets
public OrderingSystem( ) {
setSize(900, 600);
setTitle("Graph ical User Interface");
setDefaultClose Operation(EXIT_ ON_CLOSE);

toolkit = getToolkit();
Dimension size = toolkit.getScre enSize();
setLocation(siz e.width / 2 - getWidth() / 2, size.height / 2 - getHeight() / 2);

JPanel panel = new JPanel();
getContentPane( ).add(panel);
panel.setLayout (null);

priceLabel = new JLabel();
priceLabel.setB ounds(220, 10, 100, 25);
priceLabel.setT ext("0.00");

quantityTextFie ld = new JTextField();
quantityTextFie ld.setBounds(33 0, 10, 100, 35);
quantityTextFie ld.setText("0.0 0");
quantityTextFie ld.addFocusList ener(new FocusListener() {

public void focusGained(Foc usEvent event) {
}

public void focusLost(Focus Event event) {
recalculate();
}
});
subtotalLabel = new JLabel();
subtotalLabel.s etBounds(440, 10, 100, 35);
subtotalLabel.s etText("0.00");

totalLabel = new JLabel();
totalLabel.setB ounds(440, 500, 100, 35);
totalLabel.setT ext("0.00");

//Order 1

numberLabel1 = new JLabel();
numberLabel1.se tBounds(10, 65, 200, 20);
numberLabel1.se tText("Order 1");

//Pizza Shack Label
PizzaShackWidge t = new JLabel();
PizzaShackWidge t.setBounds(10, 10, 200, 20);
PizzaShackWidge t.setText("Pizz a Shack");


//Table Selector
String[] TableStrings = {"Please Select Table Number", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25"};

//table number
JComboBox TableList = new JComboBox(Table Strings);
TableList.setBo unds(200, 10, 200, 20);
TableList.setSe lectedIndex(0);
TableList.addAc tionListener(ne w ActionListener( ) {

public void actionPerformed (ActionEvent event) {
}
});



//Pizza Combo box
String[] Pizza = {"Please select a Pizza", "Cheese and tomato", "Ham and Pineapple", "Vegetarian ", "Meat Feast", "Seafood"};
PizzaCombo1 = new JComboBox(Pizza );
PizzaCombo1.set Bounds(75, 60, 150, 30);
PizzaCombo1.add ActionListener( new ActionListener( ) {

public void actionPerformed (ActionEvent event) {
if (PizzaCombo1.ge tSelectedItem() .equals("Cheese and tomato")) {
priceLabel.setT ext("3.50");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Ham and Pineapple")) {
priceLabel.setT ext("4.20");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Vegeta rian")) {
priceLabel.setT ext("5.20");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Meat Feast")) {
priceLabel.setT ext("5.80");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Seafoo d")) {
priceLabel.setT ext("5.60");
}
recalculate();
}
});
//Base Combo
String[] Base = {"Please select a Pizza Base", "Thin & Crispy", "Traditiona l", "Stuffed Crust", "Deep Pan", "Cheesey Bites"};
PizzaBaseCombo1 = new JComboBox(Base) ;
PizzaBaseCombo1 .setBounds(235, 60, 195, 30);
PizzaBaseCombo1 .addActionListe ner(new ActionListener( ) {

public void actionPerformed (ActionEvent event) {
if (PizzaCombo1.ge tSelectedItem() .equals("Thin & Crispy")) {
priceLabel.setT ext("0.0");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Tradit ional")) {
priceLabel.setT ext("0.0");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Stuffe d Crust")) {
priceLabel.setT ext("0.0");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Deep Pan")) {
priceLabel.setT ext("0.0");
} else if (PizzaCombo1.ge tSelectedItem() .equals("Cheese y Bites")) {
priceLabel.setT ext("0.0");
}
recalculate();
}
});



//Drinks Combo Box
String[] drinks = {"Please select a drink", "Cola", "Lemonade", "Fanta"};
DrinksCombo1 = new JComboBox(drink s);
DrinksCombo1.se tBounds(445, 60, 150, 30);
DrinksCombo1.ad dActionListener (new ActionListener( ) {

public void actionPerformed (ActionEvent event) {
if (DrinksCombo1.g etSelectedItem( ).equals("Cola" )) {
priceLabel.setT ext("0.90");
} else if (DrinksCombo1.g etSelectedItem( ).equals("Lemon ade")) {
priceLabel.setT ext("0.95");
} else if (DrinksCombo1.g etSelectedItem( ).equals("Fanta ")) {
priceLabel.setT ext("0.95");
}
recalculate();
}
});
//Ice or not
String[] ice = {"Ice", "With Ice", "Without Ice"};
IceCombo1 = new JComboBox(ice);
IceCombo1.setBo unds(600, 60, 80, 30);
IceCombo1.addAc tionListener(ne w ActionListener( ) {

public void actionPerformed (ActionEvent event) {
if (IceCombo1.getS electedItem().e quals("With Ice")) {
priceLabel.setT ext("0.0");
} else if (IceCombo1.getS electedItem().e quals("WithoutI ce")) {
priceLabel.setT ext("0.0");
}
recalculate();
}
});




//To Add items to the panel

panel.add(Pizza ShackWidget);
panel.add(subto talLabel);
panel.add(total Label);
panel.add(Table List);

panel.add(Drink sCombo1);
panel.add(Pizza Combo1);
panel.add(numbe rLabel1);
panel.add(Pizza BaseCombo1);
panel.add(IceCo mbo1);

panel.add(Drink sCombo2);
panel.add(Pizza Combo2);
panel.add(numbe rLabel2);
panel.add(Pizza BaseCombo2);
panel.add(IceCo mbo2);

panel.add(Drink sCombo3);
panel.add(Pizza Combo3);
panel.add(numbe rLabel3);
panel.add(Pizza BaseCombo3);
panel.add(IceCo mbo3);

panel.add(Drink sCombo4);
panel.add(Pizza Combo4);
panel.add(numbe rLabel4);
panel.add(Pizza BaseCombo4);
panel.add(IceCo mbo4);

panel.add(Drink sCombo5);
panel.add(Pizza Combo5);
panel.add(numbe rLabel5);
panel.add(Pizza BaseCombo5);
panel.add(IceCo mbo5);

panel.add(Drink sCombo6);
panel.add(Pizza Combo6);
panel.add(numbe rLabel6);
panel.add(Pizza BaseCombo6);
panel.add(IceCo mbo6);

panel.add(Drink sCombo6);
panel.add(Pizza Combo6);
panel.add(numbe rLabel6);
panel.add(Pizza BaseCombo6);
panel.add(IceCo mbo6);

panel.add(Drink sCombo7);
panel.add(Pizza Combo7);
panel.add(numbe rLabel7);
panel.add(Pizza BaseCombo7);
panel.add(IceCo mbo7);

panel.add(Drink sCombo8);
panel.add(Pizza Combo8);
panel.add(numbe rLabel8);
panel.add(Pizza BaseCombo8);
panel.add(IceCo mbo8);

panel.add(Drink sCombo9);
panel.add(Pizza Combo9);
panel.add(numbe rLabel9);
panel.add(Pizza BaseCombo9);
panel.add(IceCo mbo9);

panel.add(Drink sCombo10);
panel.add(Pizza Combo10);
panel.add(numbe rLabel10);
panel.add(Pizza BaseCombo10);
panel.add(IceCo mbo10);


}

private void recalculate() {

// recalculate subTotal
double price;
// int quantity;
double subtotal;
double total;
String subtotalOutput;
String totalOutput;
NumberFormat subtotalFormat;
NumberFormat totalFormat;

price = Double.parseDou ble(priceLabel. getText());
int quantity = Integer.parseIn t(quantityTextF ield.getText()) ;
subtotal = price * (double)quantit y / 100.0;
// see Java in Easy Steps page 129 - formating numbers
// subtotalFormat = NumberFormat.ge tNumberInstance ();
// subtotalOutput = String.valueOf( subtotal) + subtotalFormat. format(0.00);
//subtotalLabel.s etText(subtotal Output);
// now recalculate total
total = Double.parseDou ble(subtotalLab el.getText());
// NOTE: if you have many subtotal labels get the
// text from each one using:
// total = Double.parseDou ble(subtotalLab elOne.getText() )
// + Double.parseDou ble(subtotalLab elTwo.getText() );
totalFormat = NumberFormat.ge tCurrencyInstan ce(Locale.UK);
totalOutput = totalFormat.for mat(total);
totalLabel.setT ext(totalOutput );

}

/**
*
* @param args
*/
public static void main(String[] args) {
// TODO code application logic here
OrderingSystem gui = new OrderingSystem( );
gui.setVisible( true);

}
}




May 17 '09 #1
1 6737
JosAH
11,448 Recognized Expert MVP
@onlinegear
Look at line 261 of your class OrderingSystem; it is somewhere in the constructor of that class. You pass something (as a parameter) that happens to be equal to null; the calling method called the constructor at line 361.

Always read those stack traces, they tell you where the error is.

kind regards,

Jos
May 17 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
9100
by: Andy Howells | last post by:
Can anybody help me on this? I am getting the below error but have not got a clue why. The file in my classpath eing used has the class that it says is not defined. Any ideas? I am running java version 1.4.0 and WMQ Series version 5.3 with CSD04. Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/server/MQSESSION at...
7
2754
by: news | last post by:
I am pretty new to Java and I just install the JDK1.4.2 03 I am getting an error when I run the class file TestChart.class with the java.exe: Exception in thread "main" java.lang.NoClassDefFoundError: I have several class files in the directory d:\personal\java-ChartGen Chart.class ChartColourScheme.class
4
2625
oll3i
by: oll3i | last post by:
when i try to run the client application java HelloClient -ORBInitialPort 1050 -ORBInitialHost localhost i get an error exception in thread "main" java.lang.NoClassDefFoundError:HelloClient // Copyright and License import HelloApp.*; import org.omg.CosNaming.*;
9
3104
by: jith87 | last post by:
What is ths error.????? I m nw loading the JDBC driver for connection with MySql. Exception in thread "main" java.lang.NoClassDefFoundError: MySQLJDBCDriverTest
1
1767
by: GHKASHYAP | last post by:
Hi this is the exception i am getting when i am trying to run this application: Exception in thread "main" java.lang.NullPointerException thanks in advance.. package com.inventive.StockMarketTrading; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent;
4
16697
by: HaifaCarina | last post by:
here's the complete lines of errors.. Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at CsvTest.readFile(CsvTest.java:26) at Trial.main(Trial.java:24) I have no idea what to change here because I don't know what is wrong..please help me out... ...
4
14704
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar";CurrentStrobe.jar com.visionpro.currentstrobe.CurrentStrobeApp However, the statement below produces the error: java -cp...
1
13714
by: jimgym1989 | last post by:
I dont get it..why is the error: Exception in thread "main" java.util.InputMismatchException this is my code /** * @(#)textFileRead.java * * * @author * @version 1.00 2008/10/17 */
3
7635
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at sortmergejoin.MergeJoin.Field(MergeJoin.java:204) at sortmergejoin.MergeJoin.SMJoin(MergeJoin.java:84) at...
0
7371
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7716
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5305
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4925
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3425
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3420
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
676
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.