I am getting this error, but I am not really sure what it means and how can I get rid of the error. This program adds and deletes the records, as specified in input file after reading from it. Then, it writes the output to another file.
Error :
java.lang.NumberFormatException: For input string: "1 Acconci"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at ReadArtistList.getList(ReadArtistList.java:23)
at UpdateArtistList.<init>(UpdateArtistList.java:12)
at p3a.main(p3a.java:9)
p3a.java:
`import java.io.*;
//import java.lang.*;
public class p3a
{
public static void main(String args[])
{
try
{
UpdateArtistList up=new UpdateArtistList();
PrintWriter writer = new PrintWriter("C:/Users/patel/Desktop/JavaFiles/p3artists.txt");
ArtistList a=up.getUpdatedList();
ArtistNode temp=a.getListNode();
while(temp!=null)
{
writer.println(temp.toString());
temp=temp.getNext();
}
writer.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}`
UpdateArtistList.java:
import java.io.*;
//import java.lang.*;
public class UpdateArtistList
{
private ArtistList t;
public UpdateArtistList()
{
try
{
t = new ReadArtistList().getList();
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("C:/Users/patel/Desktop/JavaFiles/p2changes.txt")));
String line = reader.readLine();
while (line != null)
{
//splitting file by comma
String[] array = line.split(" ");
//checking the string of whether it is for adding new item or deleting an item
if(array[0].equals("A") || array[0].equals("a"))
{
t.add(array[1]);
}
else if(array[0].equals("D") || array[0].equals("d"))
{
//iterating through array for finding an item to delete
t.delete(Integer.parseInt(array[1]));
}
line = reader.readLine();
}
reader.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public ArtistList getUpdatedList()
{
return t;
}
}
ReadArtistList.java:
import java.io.*;
import java.lang.*;
public class ReadArtistList
{
/* public ReadArtistList()
{
}
*/ public ArtistList getList()
{
ArtistList a=new ArtistList();
try
{
//reading from file "items.txt"
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("C:/Users/patel/Desktop/JavaFiles/p1artists.txt")));
String line = reader.readLine();
while (line != null)
{
//splitting file by comma
String[] array = line.split(" ");
a.addNode(Integer.parseInt(array[0]),array[1]);
line = reader.readLine();
}
reader.close();
//return a;
}
catch(Exception e)
{
e.printStackTrace();
}
return a;
}
}