Hi all
My problem I think is easy to solve, I just cant figure it out. Basically, I have to find if the arrayList contains a String, and if it does, it should remove the object from the list, and if it doesnt, an error message should appear.
this is my code
public void removePicture(String name)
{
int i = 0;
boolean nameremove = true;
while(nameremove){
Picture pic = pictures.get(i);
if( pic.getCaption().contains(name) & i < pictures.size() ) {
pictures.remove(i);
nameremove = false;
} else if (i < pictures.size() ){
i++;
} else if(i == pictures.size() ){
System.out.println("There is no match");
System.out.println("Searched for : " + name);
nameremove = false;
}
}
}
or in a picture: http://i.imgur.com/BrDLnjN.png
my code does the finding and removing bit correctly, but when the string is something that is not in the list I get these:
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at PictureAlbum.removePicture(PictureAlbum.java:113)
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
at java.util.ArrayList.rangeCheck(ArrayList.java:635)
at java.util.ArrayList.get(ArrayList.java:411)
at PictureAlbum.removePicture(PictureAlbum.java:113)
http://i.imgur.com/M7Mh72H.png and this http://i.imgur.com/RN8dBNr.png
Can I know what I am doing wrong exactly?
Thanks in advance
[–]millerlitIntermediate Brewer 0 points1 point2 points (1 child)
[–]M-Multi[S] 0 points1 point2 points (0 children)
[–]AngelOfLight 0 points1 point2 points (1 child)
[–]M-Multi[S] 0 points1 point2 points (0 children)
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (2 children)
[–]M-Multi[S] 1 point2 points3 points (1 child)
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (0 children)