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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:53:52+00:00 2026-06-08T04:53:52+00:00

I have a list: JList characterList = new JList(characterListModel); characterListModel = new DefaultListModel(); String

  • 0

I have a list:

JList characterList = new JList(characterListModel);
characterListModel = new DefaultListModel();        
String myCharacters[]={"Dean Winchester","Sam Winchester",
            "Bobby Singer","Castiel"};
for (String myCharacter : myCharacters) {
        ((DefaultListModel) characterList.getModel()).addElement(myCharacter);  
}

And I’ve written a method, in a seperate class, to remove a character at a selected index:

public void removeCharacter() {
    DefaultListModel characterListModel = ((PlayerContentPane) IViewManager.Util.getInstance()
        .getMyContainerPane().getMyPlayerManagerPane().getContentPane())
        .getCharacterListModel();
    JList characterList = ((PlayerContentPane) IViewManager.Util.getInstance()
        .getMyContainerPane().getMyPlayerManagerPane().getContentPane())
        .getCharacterList();
    int idx = characterList.getSelectedIndex(); //<---line 62
    int size = characterListModel.getSize();
    characterListModel.remove(idx);
    if (size == 0) { 
        //do nothing
    } else { 
        if (idx == characterListModel.getSize()) {
            idx--;
        }

        characterList.setSelectedIndex(idx);
        characterList.ensureIndexIsVisible(idx);
    }

}

However when I run it with my button, I get this stack trace:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.detica.LarpDB.Controller.Controller.removeCharacter(Controller.java:62)
at com.detica.LarpDB.view.PlayerContentPane$3.actionPerformed(PlayerContentPane.java:94)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

A lot of the issues I’ve seen googling this, stem from the line: DefaultListModel characterListModel = ....
And the issue they have is that their creating a new instance of the object, now I”m only new to this whole Java thing, but this shouldn’t be an issue with me, as I’ve not made anythign new, I’ve just been specific about which object this is.

Please could someone help me untangle myself?

  • 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-08T04:53:55+00:00Added an answer on June 8, 2026 at 4:53 am

    Those 2 lines can create a lot of problems:

    DefaultListModel characterListModel = ((PlayerContentPane) IViewManager.Util.getInstance()
        .getMyContainerPane().getMyPlayerManagerPane().getContentPane())
        .getCharacterListModel();
    JList characterList = ((PlayerContentPane) IViewManager.Util.getInstance()
        .getMyContainerPane().getMyPlayerManagerPane().getContentPane())
        .getCharacterList();
    

    If any of the chained methods return null (for whatever reason) the line will throw a NullPointerException.

    I suggest you break them down in several lines and check the value of each call to see where you get the null from.

    EDIT

    Just realised that line 62 is int idx = characterList.getSelectedIndex();. It means that characterList is null.

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

Sidebar

Related Questions

I have a JList and I use a DefaultListModel to store the list entries.
I have a JList inside a Scrollpane. If you click on the list and
Currently, I have a JList listen to list selection listener. private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt)
My problem is I have a List<String> of Files and List<InetAddress> of thier IP
I have a list of items in a JList for the user to select.
I have a JList which i want to use to display a list a
I have a list of words in my Jlist and beside of every words
I have a list of words inside the JList. Every time I point the
I have two JList s. List A has these elements: 1 two 78 item4
I have a JList of users, and whenever an element in the list is

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.