public MarkList makeSubList(Student s)
{
Vector v = new Vector();
Enumeration e = markVec.elements();
while (e.hasMoreElements())
{
Mark mark = (Mark)e.nextElement();
if (s.getID().equals(mark.getSID()))
{
v.addElement(mark);
}
}
return new MarkList(v);
}
in a few cases it creates a vector of 8 or 9 objects, which is correct. My
problem is that after it reaches a point where one of the students is
missing (10 students in original list) I get arry errors. eg:
A vector of nine goes like this. the first 4 students qualify and the 5th
doesn't, the remain students do qualify. So my vector size is 9. scrolling
through my students starting at index0 is fine until i get to my fifth
student i then get this error:
Starting appletviewer for C:\au\Assignments\comp268\tme2\Registry.htm
java.lang.ArrayIndexOutOfBoundsException: 5 >= 3
at java.util.Vector.elementAt(Vector.java:427)
at MarkList.getGrade(MarkList.java:84)
at Registry.displayStud(Registry.java:442)
at Registry.handleStudForB(Registry.java:312)
at Registry.actionPerformed(Registry.java:199)
at java.awt.Button.processActionEvent(Button.java:381)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3526)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:190)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
it does show my 5th person though, i continue geting errors until i getr
back to index 0 or index 4
this driving me up the wall!!
thanks
--larry
Are you sure, that the exception occurs while accessing the
vector containing marks? You're speaking about a vector of
students. Are there two vectors and you focus on the wrong
one?
If not, then you should post more code belonging to the
exception stack-trace. Print out the elements of the
vector before the exception occur (and the size of the
vector as well).
You provide too less information to do something different
than guessing.
Regards, Lothar
--
Lothar Kimmeringer E-Mail: spam...@kimmeringer.de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)
Always remember: The answer is forty-two, there can only be wrong
questions!
What's going on at line 84 in MarkList? Are you removing elements from the
Vector while looping through it, perhaps? The error indicates you're trying
to access element 5 of a 3 element Vector.
public void handleStudForB ()
{
if (mStud)
{
sIndex = (sIndex + 1) % studList.size();
if (studMode)
displayStudent();
else
displayStud();
}
}
so then im accessing displayStud
public void displayStud ()
{
studList = studMaster.makeSubList(markListOfC);
student = studList.getStud(sIndex);
display9();
markListOfS = markMaster.makeSubList(student);
ncc = markListOfS.size();
txtNCC.setText("" + ncc);
sg = markListOfS.getGrade(sIndex);
sag = markListOfS.getAveGrade();
txtStudAG.setText("" + (round1(sag)));
txtStudGr.setText("" + (round1(sg)));
}
studList calls this one
public MarkList makeSubList(Course c)
{
Vector v = new Vector();
Enumeration e = markVec.elements();
while (e.hasMoreElements())
{
Mark mark = (Mark)e.nextElement();
if (c.getID().equals(mark.getCID()))
{
v.addElement(mark);
}
}
return new MarkList(v);
}
--larry
"Lothar Kimmeringer" <news2...@kimmeringer.de> wrote in message
news:3D8B8917...@kimmeringer.de...
[...]
Are the variables you're using defined globally?
in handleStudForB:
sIndex = (sIndex + 1) % studList.size();
Will sIndex be resetted to zero anywhere in the code? If not,
the first vector that contains lesser elemens than the previous
one will result into an ArrayIndexOutOfBoundsException.
Still it's not possible to do more than guessing. The exception
occurs in getGrade and you haven't posted it yet.
-larry
"Lothar Kimmeringer" <news2...@kimmeringer.de> wrote in message
news:3D8B97CA...@kimmeringer.de...
Your logic is questionable. You constrain sIndex to the size of studList,
then use it to reference an element in markVec. It looks like markVec is
smaller than studList.
-larry
"A Bag Of Memes" <a@b.c> wrote in message
news:vCNi9.502433$q53.16...@twister.austin.rr.com...
Then why are you using sIndex, which I assume means "student index", or
perhaps currentStudentNumber, to pry an element out of markVec?
It might be easier to understand the code if you asked Student or Course for
the grade. Maybe something like:
double grade = aStudent.getGrade(course);