cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Help Tutorial - Create a Hashtable ??

Former Member
0 Kudos

I'm new so this will be simple - I think

I'm attempting to follow the tutorial on SAP HELP located at:

http://help.sap.com/saphelp_nw04/helpdata/en/44/47b87e9d780597e10000000a155369/frameset.htm

I got threw tutorial 1 with no problem...

When I get to the "Writing Code" section of Tutorial II, writing the mySiteMap.java code, I assume I'm suppose to use the code as written in the tutorial... however my IDE (NWDS) gives me :

Syntax error on token "Hashtable", "interface", "class" expected

on this block of code, (which I copied from the tutorial):

*CODE*

public Hashtable getEnvironment(IPortalComponentRequest request ) {

Hashtable environment = new Hashtable();

IUserContext userContext = request.getUser();

if (userContext != null) {

environment.put("NavigationPrincipal", userContext);

String user = userContext.getUniqueName();

if (user != null && !user.equals("")) {

environment.put("User", user);

}

}

return environment;

}

*END CODE*

Any help is greatly appreciated

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Put the "code" into a class and make sure there is an import statement for Hashtable.

For instance,

package myPackage;

import java.util.Hashtable;

public class MyClass

{

public Hashtable getEnvironment(IPortalComponentRequest request ) {

Hashtable environment = new Hashtable();

IUserContext userContext = request.getUser();

if (userContext != null) {

environment.put("NavigationPrincipal", userContext);

String user = userContext.getUniqueName();

if (user != null && !user.equals("")) {

environment.put("User", user);

}

}

return environment;

}

}

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Marty,

could look trivial, but if you paste the code of the method getEnvironment from the link in help.sap.com there is one closing parenthesis not needed.

The error is just in the presence of that parentesis, the hashtable is ok!


public class test{

public Hashtable getEnvironment(IPortalComponentRequest request) {

    Hashtable environment = new Hashtable();
    IUserContext userContext = request.getUser();

    if (userContext != null) {
      environment.put("NavigationPrincipal", userContext);
      String user = userContext.getUniqueName();

      if (user != null && !user.equals("")) {
        environment.put("User", user);
      }//end if on user

    }//end if on userContext

    return environment;

  }//end method getEnvironment

}//<-- THIS IS WRONG!!!!! (CODE PASTED)

}//end class 

So Just remove it and it will work!

Kind Regards,

Sergio