/    Sign up×
Community /Pin to ProfileBookmark

type ArrayList is not generic;

The type ArrayList is not generic; it cannot be parameterized with arguments <String>
The type ArrayList is not generic; it cannot be parameterized with arguments <String>

I get the above errors when trying to inspect the following code in a java scrapbook:

[CODE]ArrayList<String> list = new ArrayList<String>();

Book b1 = new Book(“Great Expectations”);
Book b2 = new Book(“War and Peace”);

list.add(b1);
list.add(b2);

Person p1 = new Person();
p1.setName(“Fred”);
b1.setPerson(p1);

list[/CODE]

If I remove the <String> parameter to the ArrayList, then the code works ok.

The example from Mark Dexter’s “Eclipse and Java for Total Beginners” lesson09

[url]http://downloads.sourceforge.net/eclipsetutorial/totalbeginnerlesson09.zip[/url]

does not produce an error with the <String> parameter.

Any ideas why I have this error occurring please?

I’m running Eclipse Europa 3.3.2 on Fedora 8. I have also tried a different JVM, but still get the same error.

to post a comment
Java

9 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliAug 31.2008 — My first action would be to make sure I am using correct version of JDK that implements generics...
Copy linkTweet thisAlerts:
@chazzyAug 31.2008 — your code looks odd. why are you trying to parameterize arraylist w/ string if you're adding book's? did everything work fine when you tried his tutorial exactly as shown (when adding strings)?

did you change your JVM version (since you mentioned it in your post) in your $PATH? what does /usr/bin/java or /usr/sbin/java point to?
Copy linkTweet thisAlerts:
@jabezauthorAug 31.2008 — your code looks odd. why are you trying to parameterize arraylist w/ string if you're adding book's? did everything work fine when you tried his tutorial exactly as shown (when adding strings)?

did you change your JVM version (since you mentioned it in your post) in your $PATH? what does /usr/bin/java or /usr/sbin/java point to?[/QUOTE]


code should read something like:

<i>
</i>ArrayList&lt;String&gt; list new ArrayList&lt;String&gt;();

list.add("test1");
list.ad("test2");

list


The above works on my desktop machine, but not on my laptop. I have just ftp's the same sun JDK from desktop to laptop, but still have the error on my laptop. Comparing the java & eclipse configurations of desktop and laptop now.
Copy linkTweet thisAlerts:
@jabezauthorAug 31.2008 — I'm using Sun's java JDK identical on both machines.

I have set the java virtual machine in the eclipse.ini file with:

-vm

/usr/java/latest/bin/java

From Eclipse IDE:

Help->About Eclipse SDK->Configuration

java.runtime.name=Java(TM) SE Runtime Environment

java.runtime.version=1.6.0_06-b02

java.specification.name=Java Platform API Specification

java.specification.vendor=Sun Microsystems Inc.

java.specification.version=1.6

java.vendor=Sun Microsystems Inc.

java.vendor.url=http://java.sun.com/

java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi

java.version=1.6.0_06

java.vm.info=mixed mode, sharing

java.vm.name=Java HotSpot(TM) Client VM

java.vm.specification.name=Java Virtual Machine Specification

java.vm.specification.vendor=Sun Microsystems Inc.

java.vm.specification.version=1.0

java.vm.vendor=Sun Microsystems Inc.

java.vm.version=10.0-b22

This is the same on each machine. So Eclipse is using the JDK specified in eclipse.ini ok.

For some reason in Eclipse under:

Window->Preferences->Java->Compiler->JDK Compliance, the Compiler compliance level was set to 1.4 on my laptop, and 6.0 on the desktop. I changed this to 6.0 on the laptop and this has corrected the problem. IIRC, it was suggested to set this compiler compliance level to 1.4 in an earlier lesson of Eclipse and Java for TB's. Anyway, it's back on 6.0 again for now. Thanks for all your helpfull replies pointing me in the right direction.

BTW, Mark Dexter's Eclipse and Java tutorials are the best quality video tutorials I have every come across. He has an excellent gift in teaching Eclipse and Java. Check out the links to his free Eclipse & Java tutorials on the eclipse website at: http://www.eclipse.org/resources/
Copy linkTweet thisAlerts:
@farukMar 05.2009 — The type ArrayList is not generic; it cannot be parameterized with arguments <String>

The type ArrayList is not generic; it cannot be parameterized with arguments <String>

I get the above errors when trying to inspect the following code in a java scrapbook:

[CODE]ArrayList<String> list = new ArrayList<String>();

Book b1 = new Book("Great Expectations");
Book b2 = new Book("War and Peace");

list.add(b1);
list.add(b2);

Person p1 = new Person();
p1.setName("Fred");
b1.setPerson(p1);

list[/CODE]


############################

ArrayList<Book> list = new ArrayList<Book>();

Book b1 = new Book("Great Expectations");

Book b2 = new Book("War and Peace");

list.add(b1);

list.add(b2);

Person p1 = new Person();

p1.setName("Fred");

b1.setPerson(p1);

list[/CODE]


if you use like this

your code will be run...
Copy linkTweet thisAlerts:
@evilhiteshOct 13.2010 — hello folks

I know i am too late but still giving solution to the problem for other users who is interested

The problem is that you must import correct package of List

[B]import java.util.List;[/B]

as you probably importing list from import java.awt.List; which is for swing list.

Hope this resolves the issue ?
Copy linkTweet thisAlerts:
@zimonyiOct 13.2010 — hello folks

I know i am too late but still giving solution to the problem for other users who is interested

The problem is that you must import correct package of List

[B]import java.util.List;[/B]

as you probably importing list from import java.awt.List; which is for swing list.

Hope this resolves the issue ?[/QUOTE]


Sorry, I do not think it would in either case.

If he declares his list as ArrayList<String> he cannot place Book objects in that list, which is exactly what he did. The ArrayList he declared only accepts Strings.

Faruk's response is correct, he has to declare his list as ArrayList<Book> in order to accept Books.

Or he could omit the type altogether, and simply using ArrayList which can accept any kind of object.

Archie
Copy linkTweet thisAlerts:
@evilhiteshOct 13.2010 — Sorry, I do not think it would in either case.

If he declares his list as ArrayList<String> he cannot place Book objects in that list, which is exactly what he did. The ArrayList he declared only accepts Strings.

Faruk's response is correct, he has to declare his list as ArrayList<Book> in order to accept Books.

Or he could omit the type altogether, and simply using ArrayList which can accept any kind of object.

Archie[/QUOTE]


It is write that If he declares his list as ArrayList<String> he should not place Book objects in that list

but also notice his query that
The example from Mark Dexter's "Eclipse and Java for Total Beginners" lesson09

http://downloads.sourceforge.net/ecl...erlesson09.zip

does not produce an error with the <String> parameter.[/QUOTE]


and if this is the case than probably my solution will remove his error. try it yourself please.
Copy linkTweet thisAlerts:
@DROP_TABLE_USEROct 22.2010 — In your book class you should write an accessors method "getBookName()" that returns the field where the constructor's parameter value is stored. Or you could access that that field directly using dot notation (book.[I]fieldName[/I]) assuming it is public
×

Success!

Help @jabez spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...