Hello, first post, total noob here. Not even sure if this is the right place to post this.
I get this NullPointerException that I haven't a clue what that means. I have tried googling it and no luck understanding what this error is/does or the cause of it. One thing could be that I don't entirely understand parallel arrays. Help!
Here's my code:
------------------------------------------------------------------------------------------------------------------------------------
public class Lab10D
{
private int[]list=new int[6];
private String[]names;
private int[]age;
private int count;
public static void main(String[]args)
{
Lab10D lab=new Lab10D();
lab.input();
lab.output();
}
public void input()
{
try
{
Scanner reader=new Scanner(new File("lab10d.dat"));
reader.useDelimiter("/\r\n");
while(reader.hasNext())
{
names[count++]=reader.next();
age[count++]=reader.nextInt();
}
}
catch(IOException e)
{
System.out.println(e);
System.exit(0);
}
}
public void output()
{
for(int i=0;i<=count;i++)
{
System.out.println(names+" is "+age+" years old.");
}
}
}
------------------------------------------------------------------------------------------------------------------------------------
This is lab10d.dat
Grace Kelly/28
Bob Hope/42
Frank Lovejoy/32
William Shatner/45
Howdy Doody/12
Lester Scruggs/54
------------------------------------------------------------------------------------------------------------------------------------
And the error message.
Exception in thread "main" java.lang.NullPointerException
at Lab10D.input(Lab10D.java:26)
at Lab10D.main(Lab10D.java:15)
Edit: Firstly, the school year has been over for a month, this isn't homework, I'm just going over everything I did in class this year. And secondly, of course it's bad programming to you, like I said I'm a noob. I just finished my first year of programming.
I get this NullPointerException that I haven't a clue what that means. I have tried googling it and no luck understanding what this error is/does or the cause of it. One thing could be that I don't entirely understand parallel arrays. Help!
Here's my code:
------------------------------------------------------------------------------------------------------------------------------------
public class Lab10D
{
private int[]list=new int[6];
private String[]names;
private int[]age;
private int count;
public static void main(String[]args)
{
Lab10D lab=new Lab10D();
lab.input();
lab.output();
}
public void input()
{
try
{
Scanner reader=new Scanner(new File("lab10d.dat"));
reader.useDelimiter("/\r\n");
while(reader.hasNext())
{
names[count++]=reader.next();
age[count++]=reader.nextInt();
}
}
catch(IOException e)
{
System.out.println(e);
System.exit(0);
}
}
public void output()
{
for(int i=0;i<=count;i++)
{
System.out.println(names+" is "+age+" years old.");
}
}
}
------------------------------------------------------------------------------------------------------------------------------------
This is lab10d.dat
Grace Kelly/28
Bob Hope/42
Frank Lovejoy/32
William Shatner/45
Howdy Doody/12
Lester Scruggs/54
------------------------------------------------------------------------------------------------------------------------------------
And the error message.
Exception in thread "main" java.lang.NullPointerException
at Lab10D.input(Lab10D.java:26)
at Lab10D.main(Lab10D.java:15)
Edit: Firstly, the school year has been over for a month, this isn't homework, I'm just going over everything I did in class this year. And secondly, of course it's bad programming to you, like I said I'm a noob. I just finished my first year of programming.