Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / October 2004

Tip: Looking for answers? Try searching our database.

Can't compie code from the API examples

Thread view: 
Jimi Hulleg?rd - 27 Oct 2004 23:08 GMT
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/api/java/util/Hashtable.html

Regards
/Jimi
Paul Lutus - 28 Oct 2004 00:21 GMT
Jimi Hullegård wrote:

> Hi
>
[quoted text clipped - 4 lines]
>      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:
>
[quoted text clipped - 12 lines]
> 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.

Signature

Paul Lutus
http://www.arachnoid.com

Jimi Hulleg?rd - 28 Oct 2004 00:32 GMT
>> Hi
>>
[quoted text clipped - 9 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.