Home > Archive > Java Help > October 2004 > Can't compie code from the API examples
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Can't compie code from the API examples
|
|
| Jimi Hullegård 2004-10-27, 8:57 pm |
| 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
| |
| Paul Lutus 2004-10-27, 8:57 pm |
| 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
| |
| Jimi Hullegård 2004-10-27, 8:57 pm |
| 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
|
|
|
|
|