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 9118921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:16:14+00:00 2026-06-17T05:16:14+00:00

I have this register application where I have to make the delete option in

  • 0

I have this register application where I have to make the delete option in the basket.
Basktet

Now I have the button set in a loop so it creates a button for each product. That all works fine, but whenever I put more than one of the same item in the basket it deletes it as well instead of making the amount less. Basically I want it to be like: cars aantal: 3 and when i click the delete button for that product aantal is 2 until its one and then delete the Item. I know that is done by setting the text for the label, but the label amount is linked to the product amount. Here is my code:

Payment class:

for (int i = 0; i < products.size(); i++) {
            Product product = products.get(i);
            productdelete = product;

lblamount = new JLabel(String.valueOf(WinkelApplication.getBasket().getProductAmount(productdelete)));
            lblamount.setBounds(410, verticalPosition + i * productOffset, 70, 20);
            lblamount.setFont(WinkelApplication.FONT_10_PLAIN);
            add(lblamount);

DeleteProduct deleteproduct = new DeleteProduct();

            JButton btnDeleteproduct = new JButton("X");
            btnDeleteproduct.setBounds(380, verticalPosition + i * productOffset, 20, 20);
            btnDeleteproduct.setFont(WinkelApplication.FONT_10_BOLD);
            btnDeleteproduct.setName("" + i);
            btnDeleteproduct.addActionListener(deleteproduct);
            add(btnDeleteproduct);
}

DeleteProduct class:

public void productlist(){
    List<Product> products = WinkelApplication.getBasket().getProducts();

    for(int i = 0; i < products.size(); i++){
        deleteproduct = products.get(i);
    }
    }

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

        productamount = WinkelApplication.getBasket().getProductAmount(deleteproduct);

        if(productamount == 1){
            WinkelApplication.getBasket().deleteProduct(deleteproduct);
        }else if (productamount > 1){
            productamount--;
            WinkelApplication.getBasket().setProductAmount(productamount);
            WinkelApplication.getInstance().showPanel(new view.Payment());
        }

    }

And whenever I put this code somewhere else to load:

productamount = WinkelApplication.getBasket().getProductAmount(deleteproduct);

it gives me an error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at model.Basket.getProductAmount(Basket.java:62)
    at view.DeleteProduct.productlist(DeleteProduct.java:27)
    at view.DeleteProduct.actionPerformed(DeleteProduct.java:34)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2351)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.java:6382)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3275)
    at java.awt.Component.processEvent(Component.java:6147)
    at java.awt.Container.processEvent(Container.java:2083)
    at java.awt.Component.dispatchEventImpl(Component.java:4744)
    at java.awt.Container.dispatchEventImpl(Container.java:2141)
    at java.awt.Component.dispatchEvent(Component.java:4572)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4619)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4280)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4210)
    at java.awt.Container.dispatchEventImpl(Container.java:2127)
    at java.awt.Window.dispatchEventImpl(Window.java:2489)
    at java.awt.Component.dispatchEvent(Component.java:4572)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:704)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:663)
    at java.awt.EventQueue$2.run(EventQueue.java:661)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
    at java.awt.EventQueue$3.run(EventQueue.java:677)
    at java.awt.EventQueue$3.run(EventQueue.java:675)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:674)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
  • 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-17T05:16:15+00:00Added an answer on June 17, 2026 at 5:16 am
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    

    clearly shows that the object you are trying to get is null try to put null check
    if(WinkelApplication.getBasket()!=null)

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

Sidebar

Related Questions

I want to make a little application. That will have register, save, update, delete,
I have register my MBean app this way: ObjectName appName = new ObjectName(testpack.Application:name=myApp); MBeanServer
When I register view helpers in application.ini , I have to make sure that
I want to make an application in android. In this app user have to
I have this code to register dlls into my gac Assembly asm = Assembly.LoadFrom(argument);
I have this website (C#/ASP.NET) with a form where the user can register for
I have a win32 COM dll. I want to register this dll for different
I'm trying to make this registration work. I have a number of IEventFactory<> responsible
I have developed an application with mac and for one month now, Im trying
I want to make an application where there will be different users and each

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.