I'm having that error. This is my code:

GmailSettingsService service = new GmailSettingsService(APPLICATION_NAME, DOMAIN_NAME, null, null){
        @Override
        public void setUserCredentials(String username, String password)
                throws AuthenticationException {
            // Nothing to do here, just Overriding the old method and setting it to null so we can later setOauthCredentials to the service
        }};

    service.setOAuth2Credentials(credential);
    List users = new ArrayList();
    for (int i = 0; i < emailsData.size(); i++)
    {
        users.add(emailsData.get(0).get(i).split("@"));

        String signature = "some html code";
        String escaped = StringEscapeUtils.escapeHtml4(signature).toString();

        service.changeSignature(users, escaped);

        users.remove(0);
    }

The IDE sends me to the service.changeSignature(users, escaped); with the next exception:

Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to java.lang.String
at gmailsettings.GmailSettingsService.changeSignature(GmailSettingsService.java:723)
at Controller.updateSignature(Controller.java:306)
at Controller.main(Controller.java:126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Any solution? The program crashes where it's supposed to transform html code to encoded String and update a Gmail signature with that encoded String

  • 1
    It looks to me like you're trying to cast an Array of Strings (or a List of Strings) to a single String, which can't work. – Stultuske Apr 7 '16 at 8:29
  • The line 723 in the stack trace which line refers to in the code example above? – reallynice Apr 7 '16 at 8:31
up vote 5 down vote accepted

You are adding a string array to users.

users.add(emailsData.get(0).get(i).split("@"));

Change this with

users.add(emailsData.get(0).get(i).split("@")[0]);
  • Well, I feel braindead or something, been like half hour with this stupid error..... Thanks a lot – Alejandro93sa Apr 7 '16 at 8:34

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.