Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

identifier expected error with custom class component in arraylist

807600Jun 13 2007 — edited Jun 13 2007
Hi, this is my 7th day of learning java, so please bear with me if I use the wrong names, etc

I need to make my own type for what I want to do.
Then I want to make an ArrayList of it (because I don't know the size).
I need my new type to contain 5 variables (or is it fields?, wait, or is it elements? sigh) and have the user only give the first value for each element in the array, which is a string. the other fields must be automatically (initialized?) to the values I want.

1- am i declaring those default values at the right place?
1a - is the void in the constructer correct programming?
2- this is what is my problem. why do i get the <identifier expected> error? what's wrong with my argument? it is a string, so i'm stumped here.
    public class MyEieTipe {
        //the MyEieTipe class has 5 variables currently
        public String dieNaam;
        public float dieTelling;
        public int dieVegte;
        public boolean dieHide;
        public boolean dieBeskerm;
        //the MyEieTipe class has 1 constructor
        public void MyEieTipe(String startNaam) {
            dieNaam = startNaam;
            dieTelling = 0;
            dieVegte = 0;
            dieHide = false;
            dieBeskerm = false;
        }
    }
  
    
    ArrayList<MyEieTipe> myTipe = new ArrayList();
    myTipe.add("hello");    //gives <identifier expected> error
Any help greatly appreciated!!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2007
Added on Jun 13 2007
9 comments
375 views