Microsoft转换API:检索转换时出错:无法将“null”解析为整数

时间:2013-01-22 06:06:14

标签: android android-asynctask microsoft-translator

我正在尝试从https://github.com/rmtheis/android-ocr运行翻译服务,并在从MIcrosoft翻译Api服务中检索结果时收到以下错误

TranslatorBing(30659): Caught exeption in translation request.

W/System.err(30659): java.lang.Exception: [microsoft-translator-api] Error retrieving translation : unable to parse 'null' as integer

W/System.err(30659): at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:199)

W/System.err(30659): at com.memetix.mst.translate.Translate.execute(Translate.java:61)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.TranslatorBing.translate(TranslatorBing.java:42)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.Translator.translate(Translator.java:49)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.TranslateAsyncTask.doInBackground(TranslateAsyncTask.java:58)

W/System.err(30659): at edu.sfsu.cs.orange.ocr.language.TranslateAsyncTask.doInBackground(TranslateAsyncTask.java:1)

W/System.err(30659): at android.os.AsyncTask$2.call(AsyncTask.java:185)

W/System.err(30659): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

W/System.err(30659): at java.util.concurrent.FutureTask.run(FutureTask.java:138)

W/System.err(30659): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)

W/System.err(30659): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)

W/System.err(30659): at java.lang.Thread.run(Thread.java:1019)

W/System.err(30659): Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer

W/System.err(30659): at java.lang.Integer.parseInt(Integer.java:356)

W/System.err(30659): at java.lang.Integer.parseInt(Integer.java:332)

W/System.err(30659): at com.memetix.mst.MicrosoftTranslatorAPI.retrieveResponse(MicrosoftTranslatorAPI.java:158)

W/System.err(30659): at com.memetix.mst.MicrosoftTranslatorAPI.retrieveString(MicrosoftTranslatorAPI.java:196)

W/System.err(30659): ... 11 more

E/TranslateAsyncTask(30659): FAILURE

1 个答案:

答案 0 :(得分:0)

在日志中:

  

NumberFormatException:无法将“null”解析为整数

表示您正在尝试将空值转换为整数。在将String值转换为整数之前,请检查null为空,并使用try/catch来处理NumberFormatException

int  intnum=0;
if (strvalue !=null && !"".equals(strvalue) ){
     try {
           int  intnum = Integer.parseInt(strvalue);

         } catch (NumberFormatException e) {
            intnum=0;
            System.out.println(e.getMessage());
        }
}
else{
intnum=0;
}