nik324 Δημοσ. 30 Νοεμβρίου 2013 Δημοσ. 30 Νοεμβρίου 2013 public class Book { private String title; private int code; private List<String> authors; Book(String title, int code, List<String> authors) { this.title = title; this.code = code; this.authors = authors; } } public class Library { private String name; private List<Book> books; public void addBook(String title, int code, List<String> authors) { this.books.add( new Book( title, code, authors) ); } } public class LibraryTest { @Test public void testAddBook(){ Library l = new Library("l1"); assertNotNull(l); List<String> authors = new ArrayList<String>(); authors.add("author1"); authors.add("author2"); authors.add("author3"); authors.add("author4"); authors.add("author5"); authors.add("author6"); authors.add("author7"); assertNotNull(authors); l.addBook("title", 1 , authors); // <---- NULL pointer exception here! } } Που είναι το προβλημα εδω γτ εγω εχω τυφλωθεί και δεν το βλέπω
tr3quart1sta Δημοσ. 30 Νοεμβρίου 2013 Δημοσ. 30 Νοεμβρίου 2013 φτιαξε constructor για την library και αυτο public void addBook(String title, int code, List<String> authors) { καντο ετσι public void addBook(Book book) {
nik324 Δημοσ. 30 Νοεμβρίου 2013 Μέλος Δημοσ. 30 Νοεμβρίου 2013 Library(String name) { this.name = name; this.books = new ArrayList<Book>(); } το βρηκα.. Ελειπε αυτο ^^
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα