You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have Been trying to integrate Realtime text translation API Into my app. I followed the documentation but Upon testing application crashes saying to set the app API key
These are crash logs
Process: com.sotec.translate.app.huawei, PID: 14445
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:321)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833) Caused by: java.lang.Error: please set your app apiKey
at com.huawei.hms.mlsdk.common.MLApplication.getApiKey(MLApplication.java:412)
at com.huawei.hms.mlsdk.common.MLApplication.getAuthorizationToken(MLApplication.java:381)
at com.huawei.hms.mlsdk.translate.p.j.a(RestClientContext.java:12)
at com.huawei.hms.mlsdk.translate.p.l$b.(RestClientRequestHeaders.java:16)
at com.huawei.hms.mlsdk.translate.p.l$b.(RestClientRequestHeaders.java:1)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.c(MLRemoteTranslator.java:16)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.a(MLRemoteTranslator.java:25)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.syncTranslate(MLRemoteTranslator.java:1)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.callUrlAndParseResult(TranslationUtils.java:72)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.doInBackground(TranslationUtils.java:38)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.doInBackground(TranslationUtils.java:18)
I have enabled the MLKit service from Console As is mentioned here .
**Below is the code I Used **
` private String callUrlAndParseResult(String langFrom, String langTo, String word)
throws Exception {
// Create a text translator using custom parameter settings.
MLRemoteTranslateSetting setting = new MLRemoteTranslateSetting
.Factory()
// Set the source language code. The BCP-47 standard is used for Traditional Chinese, and the ISO 639-1 standard is used for other languages. This parameter is optional. If this parameter is not set, the system automatically detects the language.
.setSourceLangCode(langFrom)
// Set the target language code. The BCP-47 standard is used for Traditional Chinese, and the ISO 639-1 standard is used for other languages.
.setTargetLangCode(langTo)
.create();
MLRemoteTranslator mlRemoteTranslator = MLTranslatorFactory.getInstance().getRemoteTranslator(setting);
try {
return mlRemoteTranslator.syncTranslate(word);
// Processing logic for recognition success.
} catch (MLException mlException) {
// Processing logic for detection failure.
// Obtain the result code. You can process the result code and customize respective messages displayed to users.
int errorCode = mlException.getErrCode();
// Obtain the error information. You can quickly locate the fault based on the result code.
return errorCode+mlException.getMessage();
}finally {
if (mlRemoteTranslator!= null) {
mlRemoteTranslator.stop();
}
}
}
`
Please Guide Me what I am Doing Wrong, Because I cannot find any help anywhere else.
The text was updated successfully, but these errors were encountered:
I have Been trying to integrate Realtime text translation API Into my app. I followed the documentation but Upon testing application crashes saying to set the app API key
These are crash logs
Process: com.sotec.translate.app.huawei, PID: 14445
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:321)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.Error: please set your app apiKey
at com.huawei.hms.mlsdk.common.MLApplication.getApiKey(MLApplication.java:412)
at com.huawei.hms.mlsdk.common.MLApplication.getAuthorizationToken(MLApplication.java:381)
at com.huawei.hms.mlsdk.translate.p.j.a(RestClientContext.java:12)
at com.huawei.hms.mlsdk.translate.p.l$b.(RestClientRequestHeaders.java:16)
at com.huawei.hms.mlsdk.translate.p.l$b.(RestClientRequestHeaders.java:1)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.c(MLRemoteTranslator.java:16)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.a(MLRemoteTranslator.java:25)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.syncTranslate(MLRemoteTranslator.java:1)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.callUrlAndParseResult(TranslationUtils.java:72)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.doInBackground(TranslationUtils.java:38)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.doInBackground(TranslationUtils.java:18)
I have enabled the MLKit service from Console As is mentioned here
.
**Below is the code I Used **
`
Please Guide Me what I am Doing Wrong, Because I cannot find any help anywhere else.
The text was updated successfully, but these errors were encountered: