Προς το περιεχόμενο

Προτεινόμενες αναρτήσεις

Δημοσ.
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!
		
	    
	}
 
}

Που είναι το προβλημα εδω γτ εγω εχω τυφλωθεί και δεν το βλέπω

Δημοσ.

φτιαξε constructor για την library και

 

αυτο

 

 

    public void addBook(String title, int code, List<String> authors) {

 

καντο ετσι

 

 

    public void addBook(Book book) {

Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε

Πρέπει να είστε μέλος για να αφήσετε σχόλιο

Δημιουργία λογαριασμού

Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!

Δημιουργία νέου λογαριασμού

Σύνδεση

Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.

Συνδεθείτε τώρα
  • Δημιουργία νέου...