且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java错误“未使用局部变量的值";

更新时间:2023-02-22 18:04:57

好吧,错误未使用局部变量p的值.",实际上不是错误.这是您的IDE(Eclipse),警告您实际上没有在读取该变量,因此您不会从该变量接收任何输入.

Well, the error "The value of local variable p is not used.", Is not actually an error. It's your IDE (Eclipse), warning you that you aren't actually reading that variable, so you aren't receiving any input from it.

类的另一个问题是,您没有main方法.像这样

And the other problem with your class is, you don't have a main method. Like this,

public class main {
public static void main(String[] args) {
try {
Runtime rt = Runtime.getRuntime() ;
Process p = rt.exec("calc.exe") ;
} catch(Exception exc){
/*handle exception*/
}
    }
}

顺便说一句,您应该始终使用大写字母开头一个类名.所以public class main实际上应该是public class Main

And by the way, you should always start a class name with a captial letter. So public class main, should actually be public class Main