We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ArgumentException: Culture Name: xx-YY is not a supported culture on using DE Germany (Java)

We experience some issues when using Aspose on machines that have an invalid or at least unlikely Locale setting.

Code for reproducing the problem:

Locale testLocale = new Locale.Builder().setLanguage("en").setRegion("DE").build();
Locale.setDefault(testLocale);

try (InputStream in = new FileInputStream("powerpoint-1-4.pptx");
        OutputStream os = new FileOutputStream("output.pdf")) {

    Presentation presentation = new Presentation(in);
    presentation.save(os, com.aspose.slides.SaveFormat.Pdf);

} catch (Throwable ex) {
    ex.printStackTrace();
}
System.out.println("----------------- Let's try again ---------------");
try (InputStream in = new FileInputStream("powerpoint-1-4.pptx");
        OutputStream os = new FileOutputStream("output.pdf")) {

    Presentation presentation = new Presentation(in);
    presentation.save(os, com.aspose.slides.SaveFormat.Pdf);

} catch (Throwable ex) {
    ex.printStackTrace();
}

The result is:

java.lang.ExceptionInInitializerError
	at com.aspose.slides.ou.<clinit>(Unknown Source)
	at com.aspose.slides.Presentation.<clinit>(Unknown Source)
	at com.braintribe.playground.rku.SomeTests.main(SomeTests.java:243)
Caused by: class com.aspose.slides.exceptions.ArgumentException: Culture Name: en-DE is not a supported culture
com.aspose.slides.internal.e5.if.if(Unknown Source)
com.aspose.slides.internal.e5.if.<init>(Unknown Source)
com.aspose.slides.internal.e5.if.do(Unknown Source)
com.aspose.slides.internal.fq.try.try(Unknown Source)
com.aspose.slides.internal.e5.if.int(Unknown Source)
com.aspose.slides.internal.fv.long.long(Unknown Source)
com.aspose.slides.internal.fv.long.if(Unknown Source)
com.aspose.slides.ms.System.void.do(Unknown Source)
com.aspose.slides.ou.do(Unknown Source)
com.aspose.slides.ou.do(Unknown Source)
com.aspose.slides.ou.do(Unknown Source)
com.aspose.slides.ou.if(Unknown Source)
com.aspose.slides.FontData.<clinit>(Unknown Source)
com.aspose.slides.ou.<clinit>(Unknown Source)
com.aspose.slides.Presentation.<clinit>(Unknown Source)
com.braintribe.playground.rku.SomeTests.main(SomeTests.java:243)
	at com.aspose.slides.internal.e5.if.if(Unknown Source)
	at com.aspose.slides.internal.e5.if.<init>(Unknown Source)
	at com.aspose.slides.internal.e5.if.do(Unknown Source)
	at com.aspose.slides.internal.fq.try.try(Unknown Source)
	at com.aspose.slides.internal.e5.if.int(Unknown Source)
	at com.aspose.slides.internal.fv.long.long(Unknown Source)
	at com.aspose.slides.internal.fv.long.if(Unknown Source)
	at com.aspose.slides.ms.System.void.do(Unknown Source)
	at com.aspose.slides.ou.do(Unknown Source)
	at com.aspose.slides.ou.do(Unknown Source)
	at com.aspose.slides.ou.do(Unknown Source)
	at com.aspose.slides.ou.if(Unknown Source)
	at com.aspose.slides.FontData.<clinit>(Unknown Source)
	... 3 more
----------------- Let's try again ---------------
java.lang.NoClassDefFoundError: Could not initialize class com.aspose.slides.Presentation
	at com.braintribe.playground.rku.SomeTests.main(SomeTests.java:253)

There are a questions regarding this:

  1. Why is the Locale (aka Culture) important for the loading of a Powerpoint?
  2. Could you please add an option to provide the Culture in the LoadOptions?
  3. Why does the library behave differently the second time this is tried?

In general, it would be cool if Aspose would not throw an Exception when the Locale is not supported but rather use a default one.

This previous post mentions the same issue, but was resolved by setting a system wide DefaultLocale. This is not practical as it would have an impact on many other parts of the system.

Thanks!

@braintribe,

This exception occurs because en_DE is not supported culture . I suggest to use

CurrentThreadSettings.setLocale(new Locale("en", "US"));

Please check Release Notes for CurrentThreadSettings class. It is an auxiliary class that allows setting default Locale for Aspose.Slides for Java for each thread. During the loading, some internal values in the presentation are affected by CurrentLocale. Therefore, we must load them using the current locale value.

Please, use CurrentThreadSettings (https://docs.aspose.com/display/slidesjava/Aspose.Slides+for+Java+19.1+Release+Notes)

CurrentThreadSettings.setLocale(new Locale("en", "US"))

This is normal behavior in within one thread. Because the first attempt to create a presentation failed in static block of code. The second attempt throws an exception immediately.

Hi,

Thank you! I was not aware of this class. Two follow-up questions, if I may…

  1. Is there a way to get a list of Locales supported by Aspose or a check method if the current Locale is supported? Or does it correspond to the list of Locales available in Java?

  2. Am I assuming correctly that such a CurrentThreadSettings class is not available for Cells, thus no problem could arise there because of some unsupported Locale?

Thank you!

@braintribe,

Yes, It corresponds to the list of Locales supported by JDK.

Although, the similar class is not available in case of Aspose.Cells but we have option under LoadOptions as well as WorkbookSettings for this.

WorkbookSettings setting = workbook.getSettings();
setting.setLocale(Locale.GERMANY);

LoadOptions loadOptions = new LoadOptions();
loadOptions.setRegion(CountryCode.USA);
Workbook wb = new Workbook("test.xls", loadOptions);

For more about this, you may consult in Aspose.Cells forum to get more detailed response.

Hi,

Thanks again for your reply. I have still an issue with this.

I have this little test:

Locale[] allAvailableLocales = Locale.getAvailableLocales();
List<Locale> list = Arrays.asList(allAvailableLocales);

Locale defaultLocale = Locale.getDefault();

System.out.println(defaultLocale + " supported: " + list.contains(defaultLocale));
System.out.println("----------");

try (InputStream in = new FileInputStream("powerpoint-1-4.pptx");
        OutputStream os = new FileOutputStream("output.pdf")) {

    Presentation presentation = new Presentation(in);
    presentation.save(os, com.aspose.slides.SaveFormat.Pdf);

} catch (Throwable ex) {
    ex.printStackTrace();
}

When I run this test with these parameters:

-Duser.country=AT
-Duser.language=en

I get this output:

en_AT supported: true
----------
java.lang.ExceptionInInitializerError
	at com.aspose.slides.ou.<clinit>(Unknown Source)
	at com.aspose.slides.Presentation.<clinit>(Unknown Source)
	at com.braintribe.playground.rku.SomeTests.main(SomeTests.java:245)
Caused by: class com.aspose.slides.exceptions.ArgumentException: Culture Name: en-AT is not a supported culture
com.aspose.slides.internal.e5.if.if(Unknown Source)
com.aspose.slides.internal.e5.if.<init>(Unknown Source)
com.aspose.slides.internal.e5.if.do(Unknown Source)
com.aspose.slides.internal.fq.try.try(Unknown Source)
com.aspose.slides.internal.e5.if.int(Unknown Source)
com.aspose.slides.internal.fv.long.long(Unknown Source)
com.aspose.slides.internal.fv.long.if(Unknown Source)
com.aspose.slides.ms.System.void.do(Unknown Source)
com.aspose.slides.ou.do(Unknown Source)
com.aspose.slides.ou.do(Unknown Source)
com.aspose.slides.ou.do(Unknown Source)
com.aspose.slides.ou.if(Unknown Source)
com.aspose.slides.FontData.<clinit>(Unknown Source)
com.aspose.slides.ou.<clinit>(Unknown Source)
com.aspose.slides.Presentation.<clinit>(Unknown Source)
com.braintribe.playground.rku.SomeTests.main(SomeTests.java:245)
	at com.aspose.slides.internal.e5.if.if(Unknown Source)
	at com.aspose.slides.internal.e5.if.<init>(Unknown Source)
	at com.aspose.slides.internal.e5.if.do(Unknown Source)
	at com.aspose.slides.internal.fq.try.try(Unknown Source)
	at com.aspose.slides.internal.e5.if.int(Unknown Source)
	at com.aspose.slides.internal.fv.long.long(Unknown Source)
	at com.aspose.slides.internal.fv.long.if(Unknown Source)
	at com.aspose.slides.ms.System.void.do(Unknown Source)
	at com.aspose.slides.ou.do(Unknown Source)
	at com.aspose.slides.ou.do(Unknown Source)
	at com.aspose.slides.ou.do(Unknown Source)
	at com.aspose.slides.ou.if(Unknown Source)
	at com.aspose.slides.FontData.<clinit>(Unknown Source)
	... 3 more

So, I guess the list of available Locales in JDK is not sufficient to determine whether Aspose supports it.
Could you please verify whether I’m doing something wrong here?

Thanks

@braintribe,

You don’t need to do something else except CurrentThreadSettings.setLocale(). Please try using following sample.

    Locale defaultLocale = Locale.getDefault();

    
    System.out.println(defaultLocale + " supported: " + list.contains(defaultLocale));
    System.out.println("----------");

    CurrentThreadSettings.setLocale(new Locale("en-US"));
    
    try (InputStream in = new FileInputStream("powerpoint-1-4.pptx");
         OutputStream os = new FileOutputStream("output.pdf")) {

        Presentation presentation = new Presentation(in);
        presentation.save(os, com.aspose.slides.SaveFormat.Pdf);

    } catch (Throwable ex) {
        ex.printStackTrace();
    }