为什么libcore.io.ErrnoException:kill失败:在android中ESRCH(没有这样的过程)?

bik*_*nay 7 android

这是我正在使用的以下代码

try {
Runtime rnTm=Runtime.getRuntime();
Process execLang = rnTm.exec(new String[]{"getprop", "persist.sys.language"});
mCurrLocale = new BufferedReader(new InputStreamReader (execLang.getInputStream())).readLine();
execLang.destroy();
Process execCountry = rnTm.exec(new String[]{"getprop", "persist.sys.country"});
mCurrCountry = new BufferedReader(new InputStreamReader    (execCountry.getInputStream())).readLine();
execLang.destroy();
Log.e("", "Device locale: "+mCurrLocale+" Co:"+mCurrCountry);
} catch (IOException e) {
 e.printStackTrace();
 return;
 }
catch (SecurityException se) {
    se.printStackTrace();
return;
Run Code Online (Sandbox Code Playgroud)

}

It's working fine some phones and tablet.
Run Code Online (Sandbox Code Playgroud)

但有一段时间它导致我的应用程序冻结并在logcat中给出以下结果.

I/System  ( 1511): Failed to destroy process 1547
I/System  ( 1511): libcore.io.ErrnoException: kill failed: ESRCH (No such process)
I/System  ( 1511):      at libcore.io.Posix.kill(Native Method)
I/System  ( 1511):      at libcore.io.ForwardingOs.kill(ForwardingOs.java:77)
I/System  ( 1511):      at      java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:257)
Run Code Online (Sandbox Code Playgroud)

有什么解决方案吗?

小智 0

如果它在某些设备上工作而不在其他设备上工作,则意味着您必须在异常中捕获它并保持程序静默。

我建议在您的代码下面添加一个带有通用异常的捕获:

catch (Exception ge) {
 ge.printStackTrace();
 return;
 }
Run Code Online (Sandbox Code Playgroud)