public Flask[] getArtifactsByBrand(String name){ Flask[] myArray = new Flask[flasks.size()]; Iterator<Flask> it= flasks.iterator(); while(it.hasNext()){ System.out.print(it.next()); } if(flasks.contains(name)) { for(int i=0; i<myArray.length; i++) { System.out.println(myArray[i].toString()); System.out.println(flasks.toString()); } } else { System.out.println("No flasks found"); } return myArray; }
Well, this is my code. Now, I want to search for the brand name in the arraylist. When I search for the brand. it gives me the result and then the program crashes. Its gives me an NullPointerException.(I am guessing nothing's there) PLEASE HELP..I have been stuck on this problem for a whole
Enter Brand: ARgos Flask [brand=ARgos, includedCups=9, isWatertight=true, capacity=9.0, intendedLiquid=water, hasInsulation=true, netWeight=9.0, isExhibited=false]No flasks found Exception in thread "main" java.lang.NullPointerException at museum.MuseumApplication.searchByBrand(MuseumApplication.java:160) at museum.MuseumApplication.run(MuseumApplication.java:54) at museum.MuseumApplication.main(MuseumApplication.java:31)