Results 1 to 3 of 3
  1. #1
    mahedi's Avatar
    mahedi is offline Member
    Join Date
    Jan 2011
    Posts
    1
    Rep Power
    0

    Default 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........

  2. #2
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

    Default

    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!!!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. JFrame and JPanel
    By khiat in forum New To Java
    Replies: 6
    Last Post: 01-15-2011, 07:32 PM
  2. Help with JPanel and JFrame
    By weikang in forum AWT / Swing
    Replies: 3
    Last Post: 11-26-2010, 01:22 AM
  3. JPanel/JFrame
    By Mayur in forum New To Java
    Replies: 2
    Last Post: 12-20-2009, 05:07 AM
  4. How to add JFrame inside JPanel
    By niteshwar.bhardwaj in forum Java 2D
    Replies: 8
    Last Post: 12-13-2009, 08:41 PM
  5. Display output in Jframe or JPanel
    By rammurugesan in forum AWT / Swing
    Replies: 12
    Last Post: 04-14-2009, 01:45 PM

Tags for this Thread

Posting Permissions

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