0

我正在尝试从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
4

1 回答 1

0

as in log :

NumberFormatException: unable to parse 'null' as integer

means you are trying to convert an null value to integer . before converting String value to integer check it for null to empty and use try/catch for handling 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;
}
于 2013-01-22T06:53:18.667 回答