We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › weird encoding problem
Page Index Toggle Pages: 1
weird encoding problem (Read 203 times)
weird encoding problem
Feb 13th, 2009, 8:41am
 
I'm using Processing 1.0.1 on Mac OS X 10.5.6.

The following code does not work, and "UnsupportedEncodingException" occurs.
Do you have any clue?

Code:
String name = new String("some text");
byte[] utf8 = null;
utf8 = name.getBytes("UTF-8");
Re: weird encoding problem
Reply #1 - Feb 13th, 2009, 12:49pm
 
I haven't such exception thrown at runtime, I have instead a compiler error saying this exception isn't handled.
Correct code:
Code:
String name = "Sômé tèxt";
byte[] utf8 = null;
try
{
 utf8 = name.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e)
{
 println(e.getMessage());
}

Note that new String("...") is redundant...
Re: weird encoding problem
Reply #2 - Feb 13th, 2009, 3:30pm
 
Oops, I ignored the "unhandled exception" part of the error message.
Your code works great.

Thank you.
Page Index Toggle Pages: 1