Java NetBeans中的命令行参数
我在Java NetBeans中的命令行参数,java,netbeans,Java,Netbeans,我在NetBeans中遇到了命令行参数的问题,当运行这段代码时,它说 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 注意,我在NetBeans的命令行中放了一个参数 public class NewEmpty1 { public static void main(String arg[]){ System.out.println(arg[0]); } } 怎么了?您没有传递任何参数
NetBeans
中遇到了命令行参数的问题,当运行这段代码时,它说
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
注意,我在NetBeans的命令行中放了一个参数
public class NewEmpty1
{
public static void main(String arg[]){
System.out.println(arg[0]);
}
}
怎么了?您没有传递任何参数 如果您已经传递了参数,那么可能是因为您正在调用同一个包中的另一个类main方法
最好的方法是迭代
for(string s:arg)
System.out.println(s);
或
for(int i=0;i<arg.length();i++)
System.out.println(arg[i]);
for(int i=0;i
这是您的案例。args[]
为空
选中此转到项目属性在此处运行,您将看到该选项
主类
论据
现在,请确保您正在访问正确的主类…在此选项后,您有按钮浏览类路径。选择它,然后选择参数。最后,您应该能够运行程序…干杯
Ashish我猜您是通过调用另一个类main方法来编译和运行程序的……不,我肯定是通过invking类main方法编译和运行的,我已经为它添加了一个参数,但我在project中添加了一个参数properties@user1841718你的程序在不同的类中有多个主方法吗?可能是因为你正在通过另一个类main方法执行..也就是说,您可能正在将参数传递给另一个main方法是的,它有许多main方法,但我从选择类main方法可以确定,我已经为它添加了参数
subscript the string beyond its index is undefined.
public class NewMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int argslen=args.length;
int argsValue[] = new int[argslen];
for (String i:args) {
int d = 0;
argsValue[d]=Integer.parseInt(i);
System.out.print(argsValue[d]+"\t"+"\n");
}
}
}