Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Hashtable in JDK 1.2.x

Posted on 1999-07-28
5
Medium Priority
?
181 Views
Last Modified: 2013-11-23
I can't seem to get the Hashtable to work as described in the Sun JDK1.2.2 documentation.
I'm trying:

  private Hashtable users= new Hashtable();
 
  // initial user database (ahem)
  // users.put("admin", new Integer(1)); // test this because it's identical to Sun example
  users.put("leon", new String("password")); // doesn't work either
  // users.put("leon", "password");                   // My first attempt. Doesn't work either.

I get the compiler error "Type expected"

  users.put("leon", new String("password"));
                 ^
  and it points to just after the first parenthesis, whichever of the above forms I use.

BTW, I'm writing a servlet (not that that should make any difference, should it?)

Leon
0
Comment
Question by:Astroman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
Smilly earned 90 total points
ID: 1247268
remove private, if it's in a local funtion....

0
 
LVL 1

Author Comment

by:Astroman
ID: 1247269
Oops. I feel a complete fool (and I've just wasted 30 points).

I'm a total java newbie, and although your answer wasn't strictly correct, it put me in the right direction. The hashtable was private to the class, and then I was trying to add the values to it outside any method - DOH! No wonder it wanted a type...

Anyway, I've moved the population into the init method for now, so thats all sorted.

(mutter mutter, bloody new fangled languages). (Actually, entirely my own stupidity and laziness!).

Cheers,

Leon
0
 
LVL 1

Expert Comment

by:Smilly
ID: 1247270
hehehe glad I could help a little bit......

Smilly
0
 
LVL 1

Author Comment

by:Astroman
ID: 1247271
If you want a laugh, see how I got frustrated when my code:

if (aString==anotherString){
...
}

didn't work! Fortunatly I discoverd toCompare(), which seem to be just like my old favorite, strcmp().

Cheers!
0
 
LVL 1

Expert Comment

by:Smilly
ID: 1247272
Okay, thats a classic error if you are new with java....

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question