need java help again - collections

General software, Operating Systems, and Programming discussion.
Everything from software questions, OSes, simple HTML to scripting languages, Perl, PHP, Python, MySQL, VB, C++ etc.
Post Reply
User avatar
Firestorm ZERO
Member
Posts: 59
Joined: Sat Nov 25, 2000 12:00 am
Location: Toronto, Ontario CANADA

need java help again - collections

Post by Firestorm ZERO »

Ok. I making a GUI application this time. All it does is handle some data so I decided to use a LinkedList.

I imported java.util.*;

I had the following...
LinkedList stack = new LinkedList();

ok no prob. But when compiling it warns about unsafe operations but still works fine if ignore it.

So to fix that warning I did this...

LinkedList<String> stack = new LinkedList<String>();

but now it won't even recognize it.
In eclipse for "LinkedList" it says "The type LinkedList is not generic; it cannot be parameterized with arguments <String>" and for "<String>" it says "Syntax error, parameterized types are only available if source level is 5.0" and so can't compile. It gives "Exception in thread "main" java.lang.NoClassDefFoundError: Assign3"

Can anyone help me out on this.
User avatar
A_old
Posts: 10663
Joined: Sun Jan 30, 2000 12:00 am
Location: Atlanta

Post by A_old »

do you have eclipse set to compile ur project using jdk 5.0 or the 1.4 settings?
that's the first thing to check. Also, it isn't a big deal to have a warning using the first method, it just means you have to cast from object to your type as you use the data.
User avatar
Firestorm ZERO
Member
Posts: 59
Joined: Sat Nov 25, 2000 12:00 am
Location: Toronto, Ontario CANADA

Post by Firestorm ZERO »

Ok. I'll check it the settings when I get a chance.

While yes it is just a warning, but it is better programming practice to remove warnings if possible.
User avatar
A_old
Posts: 10663
Joined: Sun Jan 30, 2000 12:00 am
Location: Atlanta

Post by A_old »

some are worse is the point. i guess it depends on what the application is being written for. if it's for school or work, get rid of them. if it's for your own personal use, it doesn't matter. another thing is that wasn't a warning in 1.4.x -- they just added that w/ the 5.0 jdk, so if you're writing 1.4 code, it really shouldn't be showing up..if you're using 5.x functionality (enums, the new string stuff, etc), then that's a different story
User avatar
Firestorm ZERO
Member
Posts: 59
Joined: Sat Nov 25, 2000 12:00 am
Location: Toronto, Ontario CANADA

Post by Firestorm ZERO »

I just checked it is using jre1.5.0_06. There are no alternative JRE installed.

This is for school work so I would like to try to get this warning fixed.

All I am using is the LinkedList to add and remove nodes. The rest is just GUI stuff like buttons, textfields and scrollbar and such.
User avatar
A_old
Posts: 10663
Joined: Sun Jan 30, 2000 12:00 am
Location: Atlanta

Post by A_old »

I understand that, but you can set eclipse to enforce functionality based on Java versions.

Right click your project, go to Properties, Click on Java Compiler, now look under JDK Compliance. Make sure it's set to 5.0. Now try parameterizing the type of the LinkedList.

LinkedList<String> li = new LinkedList<String>();

Compiles just fine for me w/ out warnings w/ the Compliance level set to 5.0. I hope this helps.
User avatar
Firestorm ZERO
Member
Posts: 59
Joined: Sat Nov 25, 2000 12:00 am
Location: Toronto, Ontario CANADA

Post by Firestorm ZERO »

Thanks again Amro. That fixed it :)
User avatar
A_old
Posts: 10663
Joined: Sun Jan 30, 2000 12:00 am
Location: Atlanta

Post by A_old »

No problem bud :)
Post Reply