Java error “Value of local variable is not used”

后端 未结 7 1312
温柔的废话
温柔的废话 2020-12-06 18:00

I am really new to java (started learning 2 days ago). Sorry if this is a stupid question. I am trying to learn how to use rt.exec & similar methods so I tried to make a

7条回答
  •  情深已故
    2020-12-06 18:55

    You get that error because you don't have the main method that is used to start the java program:

    public class main {
    
    public static void main(String[] args) {
       try {
           Runtime rt = Runtime.getRuntime() ;
           Process p = rt.exec("calc.exe") ; // here, eclipse is WARINING(so you can ignore it) you that that the variable p is never used(it's just a warning)
       } catch(Exception exc) {
           /*handle exception*/
           // never do this, always put at least a System.out.println("some error here" + e); so you don't ignore a potential exception
       }
    }
    

提交回复
热议问题