Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
What is "java.lang.InstantiationException: java.util.Locale" in a portlet?
Mirto Silvio Busico, modified 7 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Hi all,
I'm trying to write localized content in a service builder generated field.
The code I have up to now is (for field5 of the default foo entity
defined as <column name="field5"
type="String" localized="true"/>):
Set<Locale> locales = LanguageUtil.getAvailableLocales();
Map<Locale, String> map = new HashMap<Locale, String>();
for (Locale locale : locales) {
String languageId = LocaleUtil.toLanguageId(locale);
String xxx = "field5";
String localeParameter = xxx.concat(StringPool.UNDERLINE).concat(languageId);
String yyy = ParamUtil.getString(actionRequest,localeParameter);
map.put(locale, yyy);
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
XMLEncoder xmlEncoder = new XMLEncoder(bos);
xmlEncoder.writeObject(map);
xmlEncoder.flush();
String field5 = bos.toString();
But the loop to assign values to map gives these errors:
java.lang.InstantiationException: java.util.Locale Continuing ... java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, ""); Continuing ... java.lang.InstantiationException: java.util.Locale Continuing ... java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "italiano"); Continuing ... java.lang.InstantiationException: java.util.Locale Continuing ... java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, ""); Continuing ... java.lang.InstantiationException: java.util.Locale Continuing ... java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, "english"); Continuing ... java.lang.InstantiationException: java.util.Locale Continuing ... java.lang.Exception: XMLEncoder: discarding statement HashMap.put(Locale, ""); Continuing ...
What I'm doing wrong?