My code is meant to take in a bunch of variables from a GUI and have them inserted into a linked list of nodes to be called when all the information is to be printed. My declaration looks like this (Just incase this information is needed).
public abstract class item{
public int ID;
public String name;
//using 2 variables for this example
public item(String name, int ID) {
this.name = name;
this.ID = ID;}
public String getName() {
return name;}
public void setName(String name) {
this.name = name;}
public int getID() {
return ID;}
public void setID(int ID) {
this.ID = ID;}
}
The problem, however, is when I try to insert the information into the first node, and any other node, using this method
public static item first(String info) {
item stuff = new item(); //"Cannot instantiate the type (class).item"
String array[] = info.split(", ");
//"ID, name" becomes "ID" "name"
stuff.ID = Integer.parseInt(array[0]);
stuff.name = array[1];
return stuff;
}
It gives me that specific error for trying to make a node to insert into my linked list. My code won't accept setting stuff equal to anything else other than null
which gives me a null pointer exception for the first variable. Is there anything I can change to fix this?