gpt4 book ai didi

android - 为什么 libcore.io.ErrnoException : kill failed: ESRCH (No such process) in android?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:32 25 4
gpt4 key购买 nike

下面是我使用的代码

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;

It's working fine some phones and tablet.

但有时它会导致我的应用程序卡住并在 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)

有什么解决办法吗?

最佳答案

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

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

catch (Exception ge) {
ge.printStackTrace();
return;
}

关于android - 为什么 libcore.io.ErrnoException : kill failed: ESRCH (No such process) in android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17485114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com