I'm new to Java. Tried to do a simple library and I've encountered a problem.
"Exception in thread "main" java.lang.NullPointerException at Book.showData(Book.java:22) at Book.main(Book.java:28) Java Result: 1"
I know how to make this work with one method. But when I use two methods - one to read and the other one to show the data, I get an error. I think I'm not reffering to string matrix correctly but I don't really know how to fix it.

import java.util.Scanner;public class Book { int bookID; String bookName; String bookAuthor; int publishDate; public String readData(){ Scanner scanner = new Scanner(System.in); System.out.println("Book's name: "); this.bookName = scanner.nextLine(); System.out.println("\nAuthor's name: "); this.bookAuthor = scanner.nextLine(); System.out.println("\nYear of publish: "); this.publishDate = scanner.nextInt(); return bookAuthor; } public void showData(){ String[] names = bookAuthor.split(" "); System.out.println(bookName+" author is "+String.format("%s %s", names[0], names[names.length-1])); } public static void main(String args[]){ new Book().readData(); new Book().showData(); }}

Check Solution