在主线程中的异常:0

huangapple go评论79阅读模式
英文:

Exception in thread "main" :0

问题

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)
英文:
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);
		}
		
	}

Keep getting this error and unsure why can someone help:

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

答案1

得分: 1

这是因为你尝试从一个空的 String[] 中获取值。

在这一行

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

你尝试获取 args[0],但在运行程序时你有提供任何 args 吗?点击此链接查看如何操作。

如果没有提供,你试图从一个大小为 0 的数组中获取第一个元素,这超出了数组的范围,因此会出现 ArrayIndexOutOfBoundsException

英文:

This happens because you're trying to get a value from an empty String[].

On this line

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

You try to get args[0] but are you giving any args when you run the program? Check this link to see how to do it.

If you're not, you're trying to get 1 item from an array with size = 0 which is more than it has, hence ArrayIndexOutOfBoundsException

huangapple
  • 本文由 发表于 2020年9月1日 15:37:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/63683310.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定