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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:33:09+00:00 2026-05-25T11:33:09+00:00

How do I fix my RemoveAction class so I don’t get the following runtime

  • 0
How do I fix my RemoveAction class so I don't get the following runtime error
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.ArrayList;
import java.io.*;


public class GuiDriver extends JFrame{
   JList channelTitleJList, itemTitleJList;
   DefaultListModel cModel, iModel;
   List<RssReader> feedList = new ArrayList<RssReader>();   
   int nextFeed=0;
   ListSelectionModel lsm;


   public void addFeed(RssReader feed){
      feedList.add(feed);
   }


   public JToolBar createToolBar(){
      JToolBar bar = new JToolBar();
      Action newToolBarButton = new AddAction("New");
      Action deleteToolBarButton = new RemoveAction("Delete");
      Action clearToolBarButton = new ClearAction("Clear");

      bar.add(newToolBarButton);  
      bar.add(deleteToolBarButton);
      bar.add(clearToolBarButton);

      bar.setFloatable(false);      
      return bar;
   }


   public JSplitPane createJSplitPane(){
      JSplitPane hSplitPane  = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,createChannelJScrollPane(), createItemJScrollPane());
      hSplitPane.setDividerLocation(150);
      return hSplitPane;
   }


   public JScrollPane createChannelJScrollPane(){            
      cModel = new DefaultListModel(); 
      channelTitleJList = new JList(cModel);
      JScrollPane channelJScrollPane = new JScrollPane(channelTitleJList);
      channelTitleJList.setVisibleRowCount(20);
      lsm = channelTitleJList.getSelectionModel();
      lsm.addListSelectionListener(new ChannelListListener());      

      return channelJScrollPane;     
   }


   public JScrollPane createItemJScrollPane(){
      iModel = new DefaultListModel();
      itemTitleJList = new JList(iModel);
      JScrollPane itemJScrollPane = new JScrollPane(itemTitleJList);
      //itemTitleJList.addListSelectionListener(new ItemListListener());

      return itemJScrollPane;
   }   


   public class AddAction extends AbstractAction{
      public AddAction(String name){
         super(name);
      }

      public void actionPerformed(ActionEvent e){
         System.out.println(getValue(Action.NAME)+" selected.");
         JOptionPane message = new JOptionPane();
         String firstInput = message.showInputDialog(null, "Enter URL");
         try{
            DumpStockPage.readXml(firstInput);
            File f = new File("RSSFeed.xml");
            addFeed(new RssReader(f));

            cModel.addElement(feedList.get(nextFeed).rssChannel.getTitle());
            nextFeed++;
            iModel.clear();
         }
         catch (IOException ee){
            System.err.println(ee);
         }
      }
   }


   public class RemoveAction extends AbstractAction{
      public RemoveAction(String name){
         super(name);
      }

      public void actionPerformed(ActionEvent e){
         cModel.removeElement(channelTitleJList.getSelectedValue());
         iModel.clear();
      } 
   }


   public class ClearAction extends AbstractAction{
      public ClearAction(String name){
         super(name);
      }

      public void actionPerformed(ActionEvent e){
         iModel.clear();
      } 
   }


   private class ChannelListListener implements ListSelectionListener{
      public void valueChanged (ListSelectionEvent e) {        
         boolean adjust = e.getValueIsAdjusting();
         if (!adjust) {
            iModel.clear();
            List<String> titles = new ArrayList<String>();
            int i = channelTitleJList.getSelectedIndex(); //the index of the selected item in the left list

            for(RssItem feed: feedList.get(i).rssChannel.items) {
                iModel.addElement(feed.getTitle());  //build a list of titles, to be shown in the right list
            }
         } 
      }
   }

/*   
   private class ItemListListener implements ListSelectionListener {
     public void valueChanged (ListSelectionEvent e) {
        boolean adjust = e.getValueIsAdjusting();
        if (!adjust) {
           int i = e.getLastIndex();
           try{ 
              JFrame w = new JFrame();
              w.setTitle("Html Display"); 
              w.setSize(1000, 600); 
              w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              w.setVisible(true); 

              JEditorPane htmlPane = new JEditorPane();
              htmlPane.setPage(feedList.get(i).rssChannel.items.get(i).getLink());
              w.add(new JScrollPane(htmlPane));
           }
           catch(Exception ee){ 
              ee.printStackTrace();
           }
        }
     }
   }
*/  

   public static void main(String[] args) { 
      EventQueue.invokeLater(new Runnable() { 
         public void run() {  
            GuiDriver frame = new GuiDriver(); 

            frame.setTitle("RSS Reader");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
            frame.add(frame.createJSplitPane(), BorderLayout.NORTH);
            frame.add(frame.createToolBar(), BorderLayout.SOUTH);

            frame.setVisible(true);
            frame.setSize(800,400);
         }   
      });  
   }
}
  • 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-25T11:33:10+00:00Added an answer on May 25, 2026 at 11:33 am

    add check to your ChannelListListener.valueChanged():

    if (i==-1) return;
    

    just before the for loop, or even better:

    if (channelTitleJList.isSelectionEmpty()) return;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any fix to avoid this exception while starting WLDF Console? Thanks. java.lang.ClassFormatError: Incompatible magic
I fix all warnings and now I have such error in my AppDelegate Class
How can you fix the following code? I want to get the slice of
How do I fix that error once and for all? I just want to
I get FIX message string (ASCII) as ByteBuffer. I parse tag value pairs and
How to fix the errors with characters in C# Employee class I am making.
# To fix the symptom How can you sum up the following columns effectively?
Please help me to fix the following odatagen issue: Command line: ./odatagen /uri=http://odata.netflix.com/v1/Catalog/ /out=/Users/sontmai/Desktop/ODatagenApp
How do I fix this? I already tried removing the R.java and cleaning the
How do I fix this error? I'm running .NET Framework v4.0.30319 so the Framework

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.