Java

Moderators: zibadian
Number of threads: 7818
Number of posts: 18218

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Weird error when removing from an array! Posted by FascinationSt on 30 Sept 2012 at 11:48 PM
else if(button.getText().equals("Remove")){
			
String text = showNum.getText(); //showNum is the JTextField
System.out.println(text); //testing purposes
int sN = Integer.parseInt(text);
System.out.println(sN); //testing
shapes.remove(sN);
		
}


Hey, I'm new here!

Anyway, the button works and everything, it's just the body of this particular if statement that I am having trouble with. I am trying to store the JTextField into an int variable, which my test shows that it has done this. However, the remove method is giving me this error "Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3".

The program: It's pretty much a simple, student program where you press buttons and it adds certain shapes to an array of shapes, which adds it to the panel. Right now, I am trying to get it to take an input value through a textField and remove it at that index.

I have spent many hours on this, googling like crazy! If anyone could help, it'd be much appreciated. :)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.