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 / General / October 2006

Tip: Looking for answers? Try searching our database.

<identifier> expected error

Thread view: 
Conor - 03 Oct 2006 11:38 GMT
Hi,

I have the following code which uses hashmaps within hashmaps to store
different views on a set of objects depending on their attributes:

class MCPStore {

    HashMap<String, HashMap> categories = new HashMap<String, HashMap>();

    HashMap<String, ArrayList> processes = new HashMap<String,
ArrayList>();

    categories.put("pname", processes);

...
}

When I compile the above code I get the following error:

$ javac MCPStore.java
MCPStore.java:11: <identifier> expected
       categories.put("processes", processes);
                     ^

Can anyone explain why this is, as I'm stumped.

Thanks,

Conor
Christopher Benson-Manica - 03 Oct 2006 15:50 GMT
> class MCPStore {
>         HashMap<String, HashMap> categories = new HashMap<String, HashMap>();
>         HashMap<String, ArrayList> processes = new HashMap<String,
> ArrayList>();
>         categories.put("pname", processes);

Perhaps you intended this to be in a function?  It can't be by itself,
in any case.

> }

Signature

C. Benson Manica           | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com      | don't, I need to know.  Flames welcome.

Oliver Wong - 04 Oct 2006 18:22 GMT
>> class MCPStore {
>>         HashMap<String, HashMap> categories = new HashMap<String,
[quoted text clipped - 5 lines]
> Perhaps you intended this to be in a function?  It can't be by itself,
> in any case.

If this is to be done once when the object is constructed, you could put it
in the constructor (or, more risky, in the static initializer):

class MCPStore {
 private final HashMap<String, HashMap> categories;

 public MCPStore() {
   categories = new HashMap<String, HashMap>();
   HashMap<String, ArrayList> processes = new HashMap<String,ArrayList>();
   categories.put("pname", processes);
 }
}

   - Oliver
Tor Iver Wilhelmsen - 04 Oct 2006 19:11 GMT
> If this is to be done once when the object is constructed, you could put it
> in the constructor (or, more risky, in the static initializer):

We,, they are instance fields so they would need to be in an instance
initializer. (Aka. code that gets put into every constructor.)
Oliver Wong - 04 Oct 2006 20:04 GMT
>> If this is to be done once when the object is constructed, you could put
>> it
>> in the constructor (or, more risky, in the static initializer):
>
> We,, they are instance fields so they would need to be in an instance
> initializer. (Aka. code that gets put into every constructor.)

   You're correct, thanks.

   - Oliver


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



©2008 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.