Results 1 to 3 of 3
- 01-22-2011, 07:31 AM #1
JPanel & JFrame Output Problem....... Can any one help?
I don't find any compile error of this program ........
But shows this runtime message........
"Exception in thread "main" java.lang.NullPointerException
at CustomerNew.<init>(CustomerNew.java:34)
at CustomerNew.main(CustomerNew.java:25)"
import javax.swing.*;
public class CustomerNew
{
// Variable for the Frame Window
static JFrame frameObject;
static JPanel panelObject;
// Variable for Label
JLabel labelCustName;
JLabel labelCustCellNo;
JLabel labelCustPackage;
JLabel labelCustAge;
// Variables for data entry control
JTextField textCustName;
JTextField textCustCellNo;
JComboBox comboCustPackage;
JTextField textCustAge;
public static void main(String args[])
{
CustomerNew customerObject=new CustomerNew();
}
public CustomerNew()
{
// Add the appropriate controls to the frame in the constructor
// Create a panel
panelObject=new JPanel();
frameObject.getContentPane().add(panelObject);
//Setting close option
frameObject.setDefaultCloseOperation(JFrame.EXIT_O N_CLOSE);
//Create and the appropriate controls
frameObject.setVisible(true);
frameObject.setSize(600,600);
//Initializing label
labelCustName=new JLabel("Customer Name : ");
labelCustCellNo=new JLabel("Cell Number : ");
labelCustName=new JLabel("Pckgege : ");
labelCustName=new JLabel("Age : ");
//Initializing data entry Control
textCustName=new JTextField(30);
textCustCellNo=new JTextField(15);
textCustAge=new JTextField(2);
String packages[]={"Executive","Standard"};
comboCustPackage=new JComboBox(packages);
//Adding controls controls for Customer Name
panelObject.add(labelCustName);
panelObject.add(textCustName);
//Adding controls controls for Cell Number
panelObject.add(labelCustCellNo);
panelObject.add(textCustCellNo);
//Adding Controls for package
panelObject.add(labelCustPackage);
panelObject.add(comboCustPackage);
//Adding controls for customer Age
panelObject.add(labelCustAge);
panelObject.add(textCustAge);
}
}
It really helpful for me..............
Waiting for response. from expert........
- 01-22-2011, 12:10 PM #2
Member
- Join Date
- Nov 2010
- Location
- New Delhi
- Posts
- 50
- Rep Power
- 0
replace
static JFrame frameObject;
with
static JFrame frameObject = new JFrame();
you have intli. one thing many times
labelCustName=new JLabel("Customer Name : "); <<<<<<<
labelCustCellNo=new JLabel("Cell Number : ");
labelCustName=new JLabel("Pckgege : ");<<<<<<<<<
labelCustName=new JLabel("Age : ");<<<<<<<
correct this one.
good luck!!!
-
Why do you have static variables anyway? Shouldn't they be instance fields?
Similar Threads
-
JFrame and JPanel
By khiat in forum New To JavaReplies: 6Last Post: 01-15-2011, 07:32 PM -
Help with JPanel and JFrame
By weikang in forum AWT / SwingReplies: 3Last Post: 11-26-2010, 01:22 AM -
JPanel/JFrame
By Mayur in forum New To JavaReplies: 2Last Post: 12-20-2009, 05:07 AM -
How to add JFrame inside JPanel
By niteshwar.bhardwaj in forum Java 2DReplies: 8Last Post: 12-13-2009, 08:41 PM -
Display output in Jframe or JPanel
By rammurugesan in forum AWT / SwingReplies: 12Last Post: 04-14-2009, 01:45 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks