【问题标题】:Exception in thread "main" :0 [duplicate]线程“main”中的异常:0 [重复]
【发布时间】:2020-09-01 07:37:36
【问题描述】:
import java.util.*;
public class Windchill {
    public static void main(String[]args)
    {
        double t=Double.parseDouble(args[0]);
        double v=Double.parseDouble(args[1]);
        double w=35.74+0.6215*t+(0.4275*t-35.75)*Math.pow(v, 0.16);
        System.out.println("Windchill =" + w);
        }
        
    }

不断收到此错误,不确定为什么有人可以提供帮助:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    at Windchill.main(Windchill.java:5)

【问题讨论】:

  • 看起来没有参数传递给您的main...args 似乎是空的。
  • 确实如此。 args 为空,因此出现此错误。
  • 你的程序运行得怎么样?
  • 也许这会有所帮助? stackoverflow.com/questions/890966/…

标签: java


【解决方案1】:

发生这种情况是因为您试图从空的String[] 中获取值。

在这条线上

double t = Double.parseDouble(args[0]);

您尝试获取args[0],但在运行程序时是否提供了argsCheck this link to see how to do it.

如果不是,您正试图从具有 size = 0 的数组中获取 1 项,这比它拥有的要多,因此是 ArrayIndexOutOfBoundsException

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 2011-07-07
    • 2012-08-25
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多