java vector

good day,i am new to programming,i got some errors.

import java.io.*;

import java.util.Vector;

class mark{

privateint mark=0;

public mark(int newMark){

this.mark=newMark;

}

publicint getMark(){

return mark;

}

}

publicclass test{

publicstaticvoid main(String[]args){

Vector mar =new Vector();

mar.addElement(new mark(3));

mar.addElement(new mark(1));

mar.addElement(new mark(2));

mar.addElement(new mark(4));

//below i get error

/*want to get 1st element in the vector*/

//mark temp=mar.elementAt(0);

/* want to print value of 1st mark*/

//System.out.println(mar.elementAt(0).getMark());

}

}

I dont know why i get errors on those 2 last lines.would be great if someone can be guide me out.

thanks alot.

Rahul

[1964 byte] By [rahulsk1947a] at [2007-11-27 9:04:18]
# 1
I haven't used Vector, but I think you need to either use a cast here or use a generic collection.Message was edited by: petes1234
petes1234a at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 2
By cast, I mean something like this:mark temp=(mark)mar.elementAt(0); System.out.println(temp.getMark());Would that work?
petes1234a at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 3
Posting the actual error message (word-for-word, not paraphrased) would help a lot.However, if you do not use Generics you need to cast the object returned from the elementAt method.
floundera at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 4
What error are there? pleaz import the detailed info.
Stone.lia at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 5
you would cast the Object to the mask type.mark temp= (mark) mar.elementAt(0); System.out.println(((mark)mar.elementAt(0)).getMark());
Stone.lia at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 6
> you would cast the Object to the mask type.> mark temp= (mark) mar.elementAt(0); > System.out.println(((mark)mar.elementAt(0)).getMark())geeze, that looks strangely familiar somehow... it's d閖?vu all over again...
petes1234a at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 7

> you would cast the Object to the mask type.

> mark temp= (mark) mar.elementAt(0);

> System.out.println(((mark)mar.elementAt(0)).getMark())

Never do that second one please.

Once I came across some code that I had to fix that had six inline casts (mainly nested Hashtables). I nearly gouged my eyes out with a plastic spoon.

cotton.ma at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 8
huh, describe me a geeze?@_@I guess he meet the error on compiling.
Stone.lia at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...
# 9
geeze = golly, gosh, holy sh韙, etc....
petes1234a at 2007-7-12 21:37:17 > top of Java-index,Java Essentials,Java Programming...