Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:57:53+00:00 2026-06-04T01:57:53+00:00

I desperately need some help.I am doing a StockManagement project.I am not able to

  • 0

I desperately need some help.I am doing a StockManagement project.I am not able to insert the items in to the database because of the error :

Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at
org.bil.service.StockManagerImpl.actionPerformed(StockManagerImpl.java:163)

I am not able to solve it. My code is long, but I think that will help you to find the issue.

public class StockManagerImpl implements ActionListener
{
    Date entryDate;
    int itemNo;
    String itemName;
    double unitPrice;
    double qty;
    double totalPrice;
    String supplier;
    String remarks;
    JTextField txtEntryDate;
    JTextField txtItemNo;
    JTextField txtItemName;
    JTextField txtUnitPrice;
    JTextField txtQty;
    JTextField txtTotalPrice;
    JTextField txtSupplier;
    JTextField txtRemarks;
    JButton BttnSaveAdded;

    StockManagerDAO stockManagerDAO;

    Toolkit kit = Toolkit.getDefaultToolkit();
    Dimension screenSize = kit.getScreenSize();
    int screenHeight = screenSize.height;
    int screenWidth = screenSize.width;
    Image img = kit.getImage("images/icon.JPG");

    JFrame newFrame;
    public void addNewItem() {

        newFrame = new JFrame("Add New");
        newFrame.setSize(220, 250);
        newFrame.setResizable(false);
        newFrame.setIconImage(img);

        JLabel lblEntryDate = new JLabel("Item EntryDate: ");
        JLabel lblItemNo = new JLabel("Item No: ");
        JLabel lblItemName = new JLabel("Item Name: ");
        JLabel lblUnitPrice = new JLabel("Item UnitPrice: ");
        JLabel lblQty = new JLabel("Item Qty: ");
        JLabel lblTotalPrice = new JLabel("Item TotalPrice: ");
        JLabel lblSupplier = new JLabel("SupplierDetails: ");
        JLabel lblRemarks = new JLabel("Remarks: ");
        JLabel lblEmpty1 = new JLabel("");
        JLabel lblEmpty2 = new JLabel("");
        //txtEntryDate = new JTextField(10);
        //  JFormattedTextField txtEntryDate = new JFormattedTextField(new SimpleDateFormat("d-M-yyyy"));
        //  txtEntryDate.setValue(new Date());

        txtEntryDate = new JFormattedTextField(new SimpleDateFormat("d-M-yyyy"));
        txtItemNo = new JTextField(10);
        txtItemName = new JTextField(10);
        txtUnitPrice = new JTextField(10);
        txtQty = new JTextField(10);
        txtTotalPrice = new JTextField(10);
        txtSupplier = new JTextField(10);
        txtRemarks = new JTextField(10);

        JButton bttnAdd = new JButton("Save");
        JButton bttnCancel = new JButton("Cancel");

        bttnAdd.addActionListener(this);
        bttnCancel.addActionListener(this);

        JPanel centerPane = new JPanel();
        JPanel bottomPane = new JPanel();

        centerPane.add(lblEntryDate);
        centerPane.add(txtEntryDate);
        centerPane.add(lblItemNo);
        centerPane.add(txtItemNo);
        centerPane.add(lblItemName);
        centerPane.add(txtItemName);
        centerPane.add(lblUnitPrice);
        centerPane.add(txtUnitPrice);
        centerPane.add(lblQty);
        centerPane.add(txtQty);
        centerPane.add(lblTotalPrice);
        centerPane.add(txtTotalPrice);
        centerPane.add(lblSupplier);
        centerPane.add(txtSupplier);
        centerPane.add(lblRemarks);
        centerPane.add(txtRemarks);
        bottomPane.add(bttnAdd);
        bottomPane.add(bttnCancel);
        centerPane.setLayout(new GridLayout(0, 2));

        newFrame.getContentPane().add(centerPane, BorderLayout.CENTER);

        newFrame.getContentPane().add(bottomPane, BorderLayout.SOUTH);
        newFrame.setLocation(screenWidth / 4, screenHeight / 4);
        newFrame.show();
        System.out.println("Show AddItem Window");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
      if(e.getActionCommand()=="Save")
      {
            System.out.println("Enterered ActionListener for AddItem");  
            entryDate = (Date)((JFormattedTextField) txtEntryDate).getValue();
            if(txtItemNo.equals(""))
            {
                itemNo = 0;
            }
            try
            {
            itemNo = Integer.parseInt(txtItemNo.getText());
            unitPrice = Double.parseDouble(txtUnitPrice.getText());
            qty = Double.parseDouble(txtQty.getText());
            }
            catch(NumberFormatException ne)
            {
                System.out.println("Integer .ParseInt error" + ne);
            }
            itemName = txtItemName.getText();
            totalPrice = unitPrice * qty;
            supplier = txtSupplier.getText();
            remarks = txtRemarks.getText();

          if (txtItemName.equals(""))
          {
                JOptionPane.showMessageDialog(null, "Please enter Item name.");
                 }
                if (txtUnitPrice.getText() == "") {
                JOptionPane.showMessageDialog(null,
                        "Please enter UnitPrice for the item");
                     }
                 if (txtQty.getText() == "") {
                 JOptionPane.showMessageDialog(null,
                        "Please enter Quantity of item to be added");
               }    else {

                Items item = new Items(entryDate, itemNo, itemName, unitPrice, qty,
                        totalPrice, supplier, remarks);
                stockManagerDAO.addNewItem(item);
                JOptionPane.showMessageDialog(null, "Item Saved");
               }
        if(e.getActionCommand()=="Cancel")
        {
            newFrame.setVisible(false);
        }
      }
    }
    }


Items.java
public class Items
{
       Date entryDate;
       int itemNo;
       String itemName;
       double unitPrice;
       double qty;
       double totalPrice;
       String supplier;
       String remarks;

      // default constructor
      public Items()
      {       
        entryDate = new Date() ;
        itemNo = 0;
        itemName="";
        unitPrice=0;
        qty=0;
        totalPrice=0;
        supplier="";
       remarks="";
      }

    public Items(Date entryDate,int itemNo,String itemName,double unitPrice,double qty,double totalPrice,String supplier,String remarks)
    {
        this.entryDate = entryDate;
        this.itemNo = itemNo;
        this.itemName = itemName;
        this.unitPrice = unitPrice;
        this.qty =qty;
        this.totalPrice=totalPrice;
        this.supplier=supplier;
        this.remarks=remarks;
    } 
    //getter and setter methods

}

Hoping these two classes are sufficient for problem solving.
Please do help me.Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:57:55+00:00Added an answer on June 4, 2026 at 1:57 am

    I don’t see any initilization for stockManagerDAO and so it is null

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I desperately need to be able to get some information from the request array
I desperately need some help on this one. I've created a <script> that closely
I am new in this field and i desperately need some guidance from u
So I'm new in python and I desperately need help. I have a file
I am in desperate need for some algorithm help when combining lists inside lists.
I have an old project from the 1990's I desperately need to compile. The
I'm new to this ExpandableListView and I desperately need your help please. I'm using
I desperately want to use server-side includes in a project I'm working on because
I am desperately in need of advice. I am attempting to mask some textboxes
Desperately need help here securing a simple Apache CXF web service. Attempts with Spring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.