我在编译程序时面临的问题是java无法识别“ .getRuntime()”方法。
这是我的代码如下:

   import java.lang.*;
    public class Temp
   {
       public static void main(String [] args)
      {
         Process p = new ProcessBuilder("cmd.exe").start();
         p = new Runtime.getRuntime().exec("cmd /c start cmd");
      } // main method
   } // Temp class


这是错误消息:

    Temp.java:7: cannot find symbol
    symbol  : class getRuntime
    location: class java.lang.Runtime
       p = new Runtime.getRuntime().exec("cmd /c start cmd");
                      ^


1个错误

最佳答案

您无法创建new运行时。简化删除new

p = Runtime.getRuntime().exec("...");


运行时具有私有构造函数。但是它有一个称为staticgetRuntime()单实例访问方法。 (单身)

10-04 11:36