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

  • Home
  • SEARCH
  • 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 3853072
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:24:47+00:00 2026-05-19T17:24:47+00:00

I’ll make this quicky and easy. I get an NPE error… Row: 0 You

  • 0

I’ll make this quicky and easy.

I get an NPE error…

Row: 0
You pressed on Item 1
Removed cancel for Item 1
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
        at inv$MousePopupListener.checkPopup(inv.java:118)
        at inv$MousePopupListener.mouseReleased(inv.java:104)
        at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:2
73)
        at java.awt.Component.processMouseEvent(Component.java:6267)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6032)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4630)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Component.dispatchEvent(Component.java:4460)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

I’ve searched high and low and I don’t know how to fix it:

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

public class inv extends JApplet implements MouseListener
{
    public JList listbox;
    public JPopupMenu popup;
    public JMenuItem item;

    public JPopupMenu useDropPopup;
    public JPopupMenu useCancelPopup;



public void init() {
   ActionListener menuListener = new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                String invAction = event.getActionCommand();


                int itemSelect = listbox.getSelectedIndex();
                Object actItem = listbox.getModel().getElementAt(itemSelect);

                System.out.println("Popup menu item [" + invAction + "] [ " + actItem + " ] was pressed.");
            }
        };

   useDropPopup = new JPopupMenu();
   useCancelPopup = new JPopupMenu();

   JMenuItem useMenuItem = new JMenuItem("Use");
   useMenuItem.addActionListener(menuListener);
   JMenuItem dropMenuItem = new JMenuItem("Drop");
   dropMenuItem.addActionListener(menuListener);
   JMenuItem cancelMenuItem = new JMenuItem("Cancel");
   cancelMenuItem.addActionListener(menuListener);

   useDropPopup.add(useMenuItem);
   useDropPopup.add(dropMenuItem);

   useCancelPopup.add(useMenuItem);
   useCancelPopup.add(cancelMenuItem);


        String listData[] =
        {
            "Item 1","Item 2","Item 3","Item 4"
        };

        listbox = new JList( listData );
        listbox.addMouseListener( new MouseAdapter()
        {
            public void mousePressed(MouseEvent e)
            {
                if ( SwingUtilities.isRightMouseButton(e) )
                {
                    System.out.println("Row: " + getRow(e.getPoint()));
                    listbox.setSelectedIndex(getRow(e.getPoint()));
                }
            }
        }
        );

        listbox.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        add(listbox);
        listbox.setVisible(true);
        listbox.setFocusable(false);


        listbox.addMouseListener(new MousePopupListener());

        useMenuItem.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent event) {
              useMenuAction(event);
           }
        };

        // ... after the init method

        public void useMenuAction(ActionEvent evt) {
           // Add specific use menu code here.
}
    }



    class MousePopupListener extends MouseAdapter
    {
        public void mousePressed(MouseEvent e)
        {
            checkPopup(e);
        }

        public void mouseClicked(MouseEvent e)
        {
            checkPopup(e);
        }

        public void mouseReleased(MouseEvent e)
        {
            checkPopup(e);
        }

        private void checkPopup(MouseEvent e)
        {
            if (e.isPopupTrigger())
            {

                int itemSelectx = listbox.getSelectedIndex();
                Object actItemx = listbox.getModel().getElementAt(itemSelectx);
                System.out.println("You pressed on " + actItemx);

            if (actItemx == "Item 1") {
                System.out.println("Removed cancel for " + actItemx);
                popup.remove(itemSelectx); // So upon right-click on Item 1, you won't see "Cancel" menu.
            }

                popup.show(inv.this, e.getX(), e.getY());
                popup.revalidate();
            }
        }
    }

    private int getRow(Point point)
    {
        return listbox.locationToIndex(point);
    }

    public void mouseEntered(MouseEvent e)
    {
    }

    public void mouseReleased(MouseEvent e)
    {
    }

    public void mousePressed(MouseEvent e)
    {
    }

    public void mouseClicked(MouseEvent e)
    {
    }

    public void mouseExited(MouseEvent e)
    {
    }
}
  • 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-05-19T17:24:48+00:00Added an answer on May 19, 2026 at 5:24 pm

    I don’t see an assignment to popup anywhere in this code, so it will always have its default value of null.

    Did you forget to say

    popup = useDropPopup;
    

    or

    popup = useCancelPopup;
    

    or maybe

    popup = new JPopupMenu();
    

    somewhere? Otherwise that routine just doesn’t know what popup you’re talking about.

    Also, since you’re mutating popup by removing an item, take care that it’s either a newly created/copied JPopupMenu, or that you put the removed item back in cases where you want it to be there.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are
I've got a string that has curly quotes in it. I'd like to replace
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.