Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

Nullpointer on Java 8 #1

Closed
slasherbane opened this issue Aug 9, 2022 · 4 comments
Closed

Nullpointer on Java 8 #1

slasherbane opened this issue Aug 9, 2022 · 4 comments

Comments

@slasherbane
Copy link

slasherbane commented Aug 9, 2022

i just try the lib today and i got a NullPointer :( can you help me please ?

try (DeepLClient client = new DeepLClient("")) {

		TextTranslationResponse translation = client
				.translate(new TextTranslationRequest("droite", TargetLanguage.AmericanEnglish));
		System.err.println(translation.getTranslations().get(0).getText());
		String result = translation.getTranslations().get(0).getText();

2022-08-09T10:05:24.874+02:00 DEBUG deepl.api.v2.logging.StdoutDeepLLogger - Sending a request:
POST https://api-free.deepl.com/v2/translate
body &text=droite&target_lang=EN-US
2022-08-09T10:05:25.427+02:00 DEBUG deepl.api.v2.logging.StdoutDeepLLogger - Received a response (1440 millis):
status 200
body
Exception in thread "main" java.lang.NullPointerException: gson.fromJson(body, Text…tionResponse::class.java) must not be null
at deepl.api.v2.json.GsonDeepLJsonSerializer.toTextTranslationResponse(GsonDeepLJsonSerializer.kt:33)
at deepl.api.v2.endpoint.TextTranslation$DefaultImpls.translate(TextTranslation.kt:94)
at deepl.api.v2.DeepLClient.translate(DeepLClient.kt:12)
at com.senefsoft.traductor.external.Translator.main(Translator.java:15)

@slasherbane
Copy link
Author

Im on JAVA 8

@seratch
Copy link
Owner

seratch commented Aug 9, 2022

The body data may be empty in the scenario for some reason. Can you enable debug level logging to see the actual response status and body data from the API? If it is an error pattern, this SDK can improve the exception to be more developer-friendly.

Also, I highly recommend revoking the API token you embedded in the above code snippet.

@slasherbane
Copy link
Author

ok, but how i can do that ?

@seratch
Copy link
Owner

seratch commented Sep 11, 2022

Thanks for reporting this. Now that there is the official Java SDK, we recommend using https://github.com/DeepLcom/deepl-java instead. Let me close this issue and archive this repo.

@seratch seratch closed this as completed Sep 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants