The constructor ProcessBuilder(String, String, Str

2019-02-26 19:01发布

问题:

In this same IDE eclipse i have two projects both have

ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/c", "command");

but in project one it is not showing compile error but in project two it is showing compile error both JRE System Library is jre1.8.0_31

The compile error is the subject-heading of this post ie.

The constructor ProcessBuilder(String, String, String) is undefined

please help?

回答1:

For me in eclipse I right clicked on my project; went to properties; chose java compiler; My compliance level was stuck at 1.4; so I bumped it up to the latest - 1.8 & it worked after that.



回答2:

I had this exact same error. I'm running eclipse in Ubuntu. My line of code with the error was

ProcessBuilder builder2 = new ProcessBuilder("cmd.exe", "/c", "rasphone -h irid");

My solution was similar to Reece's. Except my compliance level was at 1.7 (and there was no 1.8)

But I went to 1.5, and for some reason that worked. Weird.



回答3:

Try this.

 String[] commands ={"cmd.exe", "/c", "command"};
 ProcessBuilder processBuilder = new ProcessBuilder(commands);