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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:58:50+00:00 2026-06-02T04:58:50+00:00

Im getting Exception in thread AWT-EventQueue-0 java.lang.ArrayIndexOutOfBoundsException:0 and I really dont understand why. I

  • 0

Im getting “Exception in thread “AWT-EventQueue-0” java.lang.ArrayIndexOutOfBoundsException:0
and I really dont understand why.

I have these two inner classes that I use as Listeners for a JPanel called bildYta:

private class NyPlatsLyss implements ActionListener{
    public void actionPerformed(ActionEvent e){
        bildYta.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
        bildYta.addMouseListener(new BildYtaLyss());
        bildYta.addKeyListener(new EscLyss());
        bildYta.requestFocusInWindow();
        enableOperations(false);
    }
}

private class EscLyss extends KeyAdapter{
    public void keyPressed(KeyEvent e){
        if(e.getKeyCode()==KeyEvent.VK_ESCAPE){
            bildYta.setCursor(Cursor.getDefaultCursor());
            bildYta.removeMouseListener(bildYta.getMouseListeners()[0]);
            bildYta.removeKeyListener(this);
            enableOperations(true);
        }
    }
}

When I press a button it adds both of the listeners to bildYta. What I do not understand is why I get .ArrayIndexOutOfBoundsException:0 when I remove the mouse listener that I just added. Sometimes I dont even get an exception, and sometimes I do. Nothing in the rest of my code should cause any trouble because after I add those listeners, nothing else is supposed to happen in my program. It waits for either and ESC press or a mouse click

  • 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-02T04:58:51+00:00Added an answer on June 2, 2026 at 4:58 am

    This is very fragile code. The event handled by EscLyss may fire several times and only the first time it will work. Add some checks to your code. Even better, save your EscLyss instance to a field and then remove that specific instance directly. Better still, make that instance final and you can reuse it, repeatedly adding and removing it as needed. That is, in fact, the way we typically do it.

    private final MouseListener bildYtaLyss = new BildYtaLyss();
    
    private class NyPlatsLyss implements ActionListener{
      public void actionPerformed(ActionEvent e) {
        bildYta.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
        bildYta.addMouseListener(bildYtaLyss);
        EscLyss escLyss = new EscLyss();
        bildYta.addKeyListener(escLyss);
        bildYta.requestFocusInWindow();
        enableOperations(false);
      }
    }
    
    private class EscLyss extends KeyAdapter{
      public void keyPressed(KeyEvent e){
        if(e.getKeyCode()==KeyEvent.VK_ESCAPE){
          bildYta.setCursor(Cursor.getDefaultCursor());
          bildYta.removeMouseListener(bildYtaLyss);
          bildYta.removeKeyListener(this);
          enableOperations(true);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the following NullPointerException: Exception in thread AWT-EventQueue-0 java.lang.NullPointerException at com.foo.JawsFileChooser.a(SourceFile:28) at com.foo.JawsFileChooser$1.actionPerformed(SourceFile:91)
Exception in thread AWT-EventQueue-0 java.lang.OutOfMemoryError: Java heap space at java.awt.image.DataBufferInt.<init>(Unknown Source) at java.awt.image.Raster.createPackedRaster(Unknown Source)
I am getting the following exception when running an applet: Exception in thread AWT-EventQueue-4
Getting these errors in some java code http://tutorials.jenkov.com/java-multithreaded-servers/multithreaded-server.html Exception in thread Thread-0 java.lang.RuntimeException: Cannot
I'm trying out an implementation of QuickSort but getting an Exception in thread main
I'm getting an 'UnauthorizedAccesExpection - Invalid cross-thread access' exception when I try to raise
I am getting a Thread was being aborted Exception in an ASP.NET page.I am
I am getting the above error message (java.lang.UnsatisfiedLinkError) when running UISpec test case in
I am using Hibernate and getting Exception in thread main org.hibernate.ObjectNotFoundException: No row with
I'm battling an error I don't quite understand. I have a class in Java,

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.