Could someone help me with fixing this indexoutofbound error? The error is occuring at
"s += catalog.get(i).toString() + "," + catalog.get(i).getSKU() + ": " + b.getContents().get(i)+ "\n" ;"
java.lang.IndexOutOfBoundsExceptions: Index 1 Size 1 - Is the error I am getting. Thanks
import java.util.*; public class Media { public static ArrayList<MusicMedia> MakeMusicCatalog(int size) { String[]titles = { "Greatest Hits volume 1", "Greatest Hits Volume 2", "The Best of", "Love Songs", "The Early Years", "The Later Years" }; String [] artists = { "Michael Jackson", "Eminem", "The Beatles", "Shania Twain", "Limp Bizkit" }; ArrayList<MusicMedia> a = new ArrayList<MusicMedia>(); Random rn = new Random(); for (int i = 0 ; i < size; i++) { MusicMedia m ; int mediatype = rn.nextInt(3); String title = titles[rn.nextInt(titles.length)]; String artist = artists[rn.nextInt(artists.length)]; String sku = "1234-"+ i; if(mediatype == 0 ) m = new CompactDisk (title, artist, sku); else if(mediatype == 1) m = new DigitalVideoDisk(title,artist,sku); else m = new CassetteTape(title,artist,sku); a.add(m); } return a; } public static String lookupMedia(ArrayList<MusicMedia> catalog, String sku) { for(MusicMedia m : catalog) { if(m.getSKU().equalsIgnoreCase(sku)) { return sku; } } return "SKU not in catalog"; } public static String detailedInventory(ArrayList<MusicMedia> catalog, ArrayList<Bin> warehouse) { String s = ""; for(Bin b : warehouse) { s += "Bin " + b.getName()+ ":\n"; for(int i = 0 ; i < (warehouse.size()); i++) { s += catalog.get(i).toString() + "," + catalog.get(i).getSKU() + ": " + b.getContents().get(i)+ "\n" ; } s += "\n"; } return s; } public static void main(String[]args) { ArrayList<MusicMedia> catalog = MakeMusicCatalog( 10 ); ArrayList<Bin> warehouse = new ArrayList<Bin>(); Bin a = new Bin( "A" ); Bin b = new Bin( "B" ); warehouse.add( a ); warehouse.add( b ); a.add( new BinItem( "1234-0", 500 ) ); a.add( new BinItem( "1234-1", 25 ) ); a.add( new BinItem( "1234-2", 7720 ) ); b.add( new BinItem( "1234-3", 1000 ) ); System.out.println( detailedInventory( catalog, warehouse)); } }