The Artima Developer Community
Sponsored Link

Java Answers Forum
compiling error

4 replies on 1 page. Most recent reply: Mar 17, 2005 6:20 AM by vaidhyanathan.p.k

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Nikolai Neikov

Posts: 2
Nickname: shkurata
Registered: Mar, 2005

compiling error Posted: Mar 10, 2005 12:50 PM
Reply to this message Reply
Advertisement
When I try to compile a simple program I recieve this message
"unchecked call to add(E) as a member of the raw type java.util.List
for(int i=0;i<10;i++) gr.add(new Gerbil(i));"
I'm new to java and if you can tell me where is the mistake I'll be gracefull. Thanks.


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: compiling error Posted: Mar 14, 2005 11:06 AM
Reply to this message Reply
On the surface, nothing looks wrong with the java statement:

for(int i=0;i<10;i++) gr.add(new Gerbil(i));

but from the error message, its saying that the object named gr is a List type of object, which has a method called add, which adds objects.

Your statment is saying that you are adding an anonymous Gerbil object which you create inside parnetheses, new Gerbil(i)

This is invoking a constructor of the class Gerbil which is supposed to take an int type of input argument.

I can't tell much without seeing more code. I would check the code to make sure you are using the correct Object or primitive argument types in this statement.

It may be that you have to do some kind of type case on the new gerbil object.

Amol Brid

Posts: 43
Nickname: amolbrid
Registered: Feb, 2004

Re: compiling error Posted: Mar 15, 2005 2:18 AM
Reply to this message Reply
Hi,

I think you are using jdk1.5. If gr is a List the check the declaration of gr. It should be :
 List<Gerbil> gr;


Regards,
Amol Brid.

Nikolai Neikov

Posts: 2
Nickname: shkurata
Registered: Mar, 2005

Re: compiling error Posted: Mar 15, 2005 8:39 AM
Reply to this message Reply
Thanks Brid, I checked the documentation for jdk1.5 , and i found that you're right.I'm reading the "Thinking in Java" book from Bruce Eckel , but it's written for jdk1.1 and when I tried to compile them, I recieved the error message. Thanks for the advice. If I have further problems
I'll write to you.

vaidhyanathan.p.k

Posts: 3
Nickname: vaidya
Registered: Mar, 2005

Re: compiling error Posted: Mar 17, 2005 6:20 AM
Reply to this message Reply
hi,
see whatever u have done the same thing i tried in jdk1.5.0
i didnt get any error message

class gabriel
{
gabriel(int i)
{

}
}
public class testlist {
public static void main(String args[])
{
List ls=new ArrayList();
for(int i=0;i<5;i++)
ls.add(new gabriel(i));
}

could u please check whether the above program is the one u tried or some other thing

Flat View: This topic has 4 replies on 1 page
Topic: need help again Previous Topic   Next Topic Topic: how do I link gui's together?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use