Benches Uncategorized

1

Illegal escape character in Java

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I am trying to seperate 2 credentials by a semicolon(;) , but that gives me error

java.lang.NullPointerException
at java.net.URLEncoder.encode(URLEncoder.java:187)
at ITunesU.getAuthorizationToken(ITunesU.java:318)
at ITunesUstudent.main(ITunesUstudent.java:532)
Exception in thread "main"

So I tried putting before the semicolon as follows
String Credential = "Student@urn:mace:itunesu.com:sites:umb.edu:classes:fall07:cs646;Student@urn:m ace:itunesu.com:sites:umb.edu:classes:fall07:cs646";

This gives me compile error:
ITunesU_student.java:484: illegal escape character

Does anyone know how to seperate 2 credentials with the semicolon using JAVA ?

1 reply

Sign in or join Beachball Help to reply.

  1. 0

    Apple Support Community member

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Sushant,

    I do not know why Java's URL encoder is bailing on you because of a semicolon ... but let's say, for whatever reason, it doesn't like semicolons. You have a simple workaround ...

    String FirstCredential = "Student@urn:mace:itunesu.com:sites:umb.edu:classes:fall07:cs646";
    String SecondCredential = "Student@urn:mace:itunesu.com:sites:umb.edu:classes:fall07:cs646";

    String encodedFirstCredential = encode(FirstCredential);
    String encodedSecondCredential = encode(SecondCredential);

    String FinalCredential = encodedFirstCredential + ";" + encodedSecondCredential;

    Something like that ... basically, what I'm suggesting is that you encode each credential sepearately, then concatentate with a semicolon. This way, if the "encode" routine is bombing on the semicolon, you're taking it out of the picture.