I want to add data to ArrayList object. In my code addBook() method will be show Input Dialogue Box and pass this string to isbn variable. Now there is need to add isbn variable data to ArrayList which is reside in BookInfoNew() constructor but list object not found in addBook() method. (list.add(isbn))
kindly help me.
import java.util.*;
import javax.swing.JOptionPane;
public class BookInfoNew {
private static String isbn;
private static String bookName;
private static String authorName;
public static int totalBooks = 0;
//default constructor
public BookInfoNew() {
List<String> list = new ArrayList<String>(); //create ArrayList
}
//Parameterized constructor
public void BookInfoNew(String x, String y, String z) {
isbn = x;
bookName = y;
authorName = z;
}
//add book method
public void addBook() {
String isbn = JOptionPane.showInputDialog("Enter ISBN");
//add books data to ArrayList
list.add(isbn);
}
}
listis a local variable, which only exists in your non parameter constructor.static?addBook()doesn't even have access tolist