Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Can't compie code from the API examples
Hi

I'm trying to compile the following code, copied from the API (1.5.0)*:

Hashtable numbers = new Hashtable();
numbers.put("one", new Integer(1));
numbers.put("two", new Integer(2));
numbers.put("three", new Integer(3));

And I get the following error messages:

C:\KTH\algoritmer\HashtableTest.java:13: <identifier> expected
numbers.put("one", new Integer(1));
^
C:\KTH\algoritmer\HashtableTest.java:14: <identifier> expected
numbers.put("two", new Integer(2));
^
C:\KTH\algoritmer\HashtableTest.java:15: <identifier> expected
numbers.put("three", new Integer(3));
^

The way I understand it, Hashtable is generic (or whatever it's called) in
1.5, since it says Class Hashtable<K,V>.
But then how do I use Hashtable? The example code doesn't work. Or am I
doing something else wrong?

* http://java.sun.com/j2se/1.5.0/docs.../Hashtable.html

Regards
/Jimi



Report this thread to moderator Post Follow-up to this message
Old Post
Jimi Hullegård
10-28-04 01:57 AM


Re: Can't compie code from the API examples
Jimi Hullegård wrote:

> Hi
>
> I'm trying to compile the following code, copied from the API (1.5.0)*:
>
>      Hashtable numbers = new Hashtable();
>      numbers.put("one", new Integer(1));
>      numbers.put("two", new Integer(2));
>      numbers.put("three", new Integer(3));

You tried to compile this, as shown, copied directly from the online
example? Did you wrap it in a class? Did you import anything? Where is the
rest of your code?

>
> And I get the following error messages:
>
> C:\KTH\algoritmer\HashtableTest.java:13: <identifier> expected
>      numbers.put("one", new Integer(1));
>                 ^
> C:\KTH\algoritmer\HashtableTest.java:14: <identifier> expected
>      numbers.put("two", new Integer(2));
>                 ^
> C:\KTH\algoritmer\HashtableTest.java:15: <identifier> expected
>      numbers.put("three", new Integer(3));
>                 ^
>
> The way I understand it, Hashtable is generic (or whatever it's called) in
> 1.5, since it says Class Hashtable<K,V>.
> But then how do I use Hashtable? The example code doesn't work. Or am I
> doing something else wrong?

We can't tell. Post a complete, short example program that includes the
above snippet, so we can see it in context.

--
Paul Lutus
http://www.arachnoid.com


Report this thread to moderator Post Follow-up to this message
Old Post
Paul Lutus
10-28-04 01:57 AM


Re: Can't compie code from the API examples
Paul Lutus wrote:
> Jimi Hullegård wrote:
> 
>
> You tried to compile this, as shown, copied directly from the online
> example? Did you wrap it in a class? Did you import anything?
>Where is the rest of your code?

I'm terribly sorry. My misstake. Sure I imported everything needed and
wrapped it in a class, but I forgot to wrap it in a method aswell... duh...
hmm, I blame the late hour (1.30am). sorry!
everything works now.

/Jimi



Report this thread to moderator Post Follow-up to this message
Old Post
Jimi Hullegård
10-28-04 01:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:03 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.