Am updating classes.
Show me where it's going wrong and how to fix it?
package DiscreteMathProject;
import java.util.ArrayList;
import java.util.Random;
/**
Type: Posts; User: javapenguin
Am updating classes.
Show me where it's going wrong and how to fix it?
package DiscreteMathProject;
import java.util.ArrayList;
import java.util.Random;
/**
Exception in thread "main" java.lang.NullPointerException
at DiscreteMathProject.Class.getStudentsInClass(Class.java:122)
at DiscreteMathProject.Class.toString(Class.java:113)
at...
public String getStudentsInClass()
{
for (int i = 0; i < aList.size(); i++)
{
aList2.add(aList.get(i).getName());
}
If I change it to that in getStudentsInClass I get a Null Pointer Exception
Where do I change this?
In my MainClass or in Class?
If the Class class, inside what method?
Ok, what is that doing?
How would I use the for each loop?
I'm not very familiar with those.
Where would it go?
The size of class Sleeping 101 is 15
The size of class Partying 202 is 24
The size of class Discrete Math is 24
The size of class Rocket Science is 15
The size of class Introduction to Data...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 15
at DiscreteMathProject.MainClass.<init>(MainClass.java:213)
at DiscreteMathProject.MainClass.main(MainClass.java:836)...
I think that the number of students in the brackets, the number of students the class says there are in the class that the toString() generates, and the class size are all not matching.
Ok, these are my class sizes, in order.
The ones that did print out right are also in order in the classes array.
20
18
15
17
15
16
The class: Sleeping 101 is at 8:00 a.m.and has 15 students. The students in it are: [Adolf Hitler, Paul Adcock, Albert Einstein, Martin Luther, Darth Vader, John Wayne, Julius Ceasar, Spongebob...
What's wrong with this:
public String getStudentsInClass()
{
for (int i = 0; i < getSize(); i++)
{
aList2.add(aList.get(i).getName()); // it points to...
No, it's not that it'll accept class sizes of only 15. This is proof.
The class: Sleeping 101 is at 2:00 p.m.and has 15 students. The students in it are: [Susan B. Anthony, Martin Luther, Peter...
The class: Partying 202 is at 12:30 p.m.and has 15 students. The students in it are: [Darth Vader, Sherlock Holmes, Joe McDonald, Martin Luther, Abraham Lincoln, Albert Einstein, Julius Ceasar,...
Hey, I'm starting a new thread since my thread "Using Random class" may or may not have the error due to the class Random. More likely it's something wrong with one of my ArrayLists.
package...