有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

执行“put”时发生java异常

我试图通过一个应用程序以编程方式运行adb shell命令来更改rtt_calling_mode变量值,但遇到了这个错误

 Exception occurred while executing 'put':
 java.lang.NullPointerException
    at java.util.Objects.requireNonNull(Objects.java:220)
    at com.安卓.server.appop.AppOpsService.checkPackage(AppOpsService.java:2969)
    at 安卓.app.AppOpsManager.checkPackage(AppOpsManager.java:7697)
    at 安卓.content.ContentProvider.getCallingPackage(ContentProvider.java:954)
    at com.安卓.providers.settings.SettingsProvider.mutateSecureSetting(SettingsProvider.java:1732)
    at com.安卓.providers.settings.SettingsProvider.insertSecureSetting(SettingsProvider.java:1652)
    at com.安卓.providers.settings.SettingsProvider.call(SettingsProvider.java:412)
    at 安卓.content.ContentProvider.call(ContentProvider.java:2448)
    at 安卓.content.ContentProvider$Transport.call(ContentProvider.java:517)
    at com.安卓.providers.settings.SettingsService$MyShellCommand.putForUser(SettingsService.java:375)
    at com.安卓.providers.settings.SettingsService$MyShellCommand.onCommand(SettingsService.java:277)
    at 安卓.os.BasicShellCommandHandler.exec(BasicShellCommandHandler.java:98)
    at 安卓.os.ShellCommand.exec(ShellCommand.java:44)
    at com.安卓.providers.settings.SettingsService.onShellCommand(SettingsService.java:49)
    at 安卓.os.Binder.shellCommand(Binder.java:929)
    at 安卓.os.Binder.onTransact(Binder.java:813)
    at 安卓.os.Binder.execTransactInternal(Binder.java:1159)
    at 安卓.os.Binder.execTransact(Binder.java:1123)

在A10上运行时,我能够完美地运行此命令,它将更改RTT变量,就像我通过命令提示符运行命令“adb外壳设置放置安全RTT_调用_mode0 1”。但是现在在A11版本上,我收到了这个错误。我不确定是什么原因导致了这个问题,也不清楚为什么现在“put”出现了问题。也不确定NullPointerException来自何处。有人知道是什么导致了这个问题吗?下面是运行时抛出错误的代码

public static String setRealTimeText(int simSlot, int enabled){
        String command = "settings put secure rtt_calling_mode" + slot +  " " + enabled;

        try {
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
            BufferedReader errorOutput = new BufferedReader(new InputStreamReader(process.getErrorStream()));

            //get the error output
            String s = "";
            String outputString = "";

            if (errorOutput.readLine() != null) {
                while ((s = errorOutput.readLine()) != null) {
                    outputString += " " + s + "\n";
                }
                return outputString;
            }

            //get the console output
            while ((s = output.readLine()) != null) {
                outputString += "- " + s + "\n";
            }
            return "RTT was enabled"

        } catch (Exception e) {
            e.printStackTrace();
            return e.toString();
        }
    }

共 (0) 个答案