Exception in thread "main" java.lang.NumberFormatException:For input String
this is a code about arrylist. but when I debug it.it metion:Exception in thread "main" java.lang.NumberFormatException:For input String at java.lang.NumberFormatException.forInputString(numberFomatExceptionio java:48)
at java.lang.Integer.parseInt(integer.java:468)
at java.lang.Integer.parseInt(integer.java:497)
at Get.getInt(manerger.java:208)
at LinkList.insertFirst(manager.java:94)
at manager.main(manager.java;20)
this is my code:
import java.io.*;
import java.lang.*;
public class manager
{
public static void main(String args[]) throws IOException
{
LinkList list=new LinkList();
System.out.println("input S can scan the grade\ninput D can delete one entry\ninput U can update the entry\ninput A can add one entry\ninput E can end");
int cr=System.in.read();
switch(cr)
{
case 'A':
list.insertFirst();break;//this is 20 row
case 'S':
System.out.println("input the s");break;
case 'D':
System.out.println("input the d");break;
case 'U':
System.out.println("input the u");break;
}
}
}
class Link
{
public int number;
public String name=new String();
public int chs;
public int eng;
public int math;
public Link next;
public Link(int number,String name, int chs,int eng,int math)
{
this.number=number;
this.name=name;
this.chs=chs;
this.eng=eng;
this.math=math;
}
public Link()
{
this(0,"",0,0,0);
}
public void displayLink()
{
System.out.println(number + " "+name+ " "+chs+ " "+eng+ " "+math+ " ");
}
}
class LinkList
{
public Link first;
public LinkList()
{
first = null;
}
public boolean isEmpty()
{
return first==null;
}
public void displayList()
{
System.out.println("");
Link current=first;
while(current!=null)
{
current.displayLink();
current=current.next;
}
System.out.println("");
}
public Link insertFirst() throws IOException
{
Get getdata=new Get();
int number=getdata.getInt();//this is 94 row
String name=getdata.getString();
int chs=getdata.getInt();
int eng=getdata.getInt();
int math=getdata.getInt();
Link newLink = new Link(number,name,chs,eng,math);
first=newLink;
return first;
}
public Link find(int key)
{
Link current=first;
while(current.number!=key)
{
if(current.next==null)
return null;
else
current=current.next;
}
return current;
}
public Link update(int key) throws IOException
{
Link current=first;
while(current.number!=key)
{
if(current.next==null)
return null;
else
{
System.out.println("Input the first letter of the subject:");
int c=System.in.read();
Get get=new Get();
switch(c)
{
case 'c':
current.chs=get.getInt();break;
case 'e':
current.eng=get.getInt();break;
case 'm':
current.math=get.getInt();break;
}
}
}
return current;
}
public float average(char key)
{
Link current=first;
float total=0;
float average=0;
float counter=0;
if(current==null)
return 0;
while(current!=null)
{
switch(key)
{
case 'c':
total=current.chs+current.next.chs;break;
case 'e':
total=current.eng+current.next.eng;break;
case 'm':
total=current.math+current.next.math;break;
}
current=current.next.next;
counter++;
}
average=total/counter;
return average;
}
public Link delete(int key)
{
Link current=first;
Link previous=first;
while(current.number!=key)
{
if(current.next==null)
return null;
else
{
previous=current;
current=current.next;
}
}
if(current==first)
first=first.next;
else
previous.next=current.next;
return current;
}
}
class Get
{
public static String getString() throws IOException
{
System.out.println("Input your name:");
InputStreamReader str = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(str);
String s = br.readLine();
return s;
}
public static int getInt() throws IOException
{
System.out.println("Input your data:");
String st = getString();
return Integer.parseInt(st);//this is 208 row
}
}

