2

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

2
  • 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. Commented Apr 7, 2016 at 8:29
  • The line 723 in the stack trace which line refers to in the code example above? Commented Apr 7, 2016 at 8:31

1 Answer 1

5

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]);
1
  • Well, I feel braindead or something, been like half hour with this stupid error..... Thanks a lot Commented Apr 7, 2016 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.