title: LDAP java error: adding entry.javax.naming.directory.NoSuchAttributeException
body: <p>I have a problem adding an entry in LDAP, precisely I want to add a user.</p>
  
  <pre><code>class AddUser {
  
      public static void main(String[] args) {
  
          String userName = "manager";
          String password = "pass";
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, "ldap://192.168.10.45:389/dc=mydc,dc=local");
          env.put(Context.SECURITY_AUTHENTICATION, "simple");
          env.put(Context.SECURITY_PRINCIPAL, new String("mydc" + "\\" + userName));
          env.put(Context.SECURITY_CREDENTIALS, password);
          // env.put(Context.REFERRAL, "follow");
          // entry's DN
          String entryDN = "cn=NewUser, dc=mydc, dc=local";
          // entry's attributes
          Attribute cn = new BasicAttribute("cn", "NewUser");
          Attribute sn = new BasicAttribute("sn", "Smith");
          Attribute mail = new BasicAttribute("mail", "newuser@foo.com");
          Attribute phone = new BasicAttribute("telephoneNumber", "+1 222 3334444");
          Attribute uid = new BasicAttribute("uid", "nsmith");
          Attribute userPassword = new BasicAttribute("userPassword", "pwd1");
          Attribute oc = new BasicAttribute("objectClass");
          oc.add("dcObject");
          oc.add("person");
          oc.add("inetOrgPerson");
  
          DirContext ctx = null;
  
          try {
              // get a handle to an Initial DirContext
              ctx = new InitialDirContext(env);
  
              // build the entry
              Attributes entry = new BasicAttributes();
              entry.put(cn);
              entry.put(sn);
              entry.put(mail);
              entry.put(phone);
              entry.put(uid);
              entry.put(userPassword);
              entry.put(oc);
  
              // Add the entry
              ctx.createSubcontext(entryDN, entry);
              System.out.println("AddUser: added entry " + entryDN + ".");
  
          } catch (NamingException e) {
              System.err.println("AddUser: error adding entry." + e);
          }
      }
  }
  </code></pre>
  
  <p>I got the following error:</p>
  
  <blockquote>
    <p>AddUser: error adding <br/>
    entry.javax.naming.directory.NoSuchAttributeException: [LDAP: error code 16 - 00000057: LdapErr: DSID-0C090C3E, comment: Error in attribute conversion operation, data 0, v1db1 ]; remaining name cn=NewUser, dc=mydc, dc=local</p>
  </blockquote>
  
  <p>I don't know where is the error. Can be only a bad input about the attributes?</p>