【问题标题】:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at HelloWorld.main(HelloWorld.java:15) [closed]线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 0 at HelloWorld.main(HelloWorld.java:15) [关闭]
【发布时间】:2014-11-14 07:48:13
【问题描述】:

我无法运行我的班级项目。我对此无药可救,有人可以帮忙吗?

http://i.stack.imgur.com/0yr8J.png

import java.util.Random;


public class HelloWorld {

    public static String[] intensities = { "00", "33", "66", "99", "CC", "FF" };

    public static String randomColor() {
        Random a = new Random();
        return "#" + intensities[a.nextInt(6)] + intensities[a.nextInt(6)]
                + intensities[a.nextInt(6)];
    }

    public static void main(String[] args) {
        int nRows = Integer.parseInt(args[0]);
        int nCols = Integer.parseInt(args[1]);
        String[] colArray = new String[10];
        for (int c = 0; c < 10; c++) {
            colArray[c] = randomColor();
        }
        System.out.println("<table border='1'>\n");
        for (int i = 1; i <= nRows; i++) {
            System.out.println("<tr>");
            for (int j = 1; j <= nCols; j++) {
                int result = i * j;
                int colorNum = result * 10 / (nRows * nCols +1);
                System.out.println("<td bgcolor='" + colArray[colorNum] + "'>"
                        + result + "</td>");

            }
            System.out.println("</tr>\n");
        }
        System.out.println("</table>");

    }
}

我无法运行我的班级项目。我对此无药可救,有人可以帮忙吗?

http://i.stack.imgur.com/0yr8J.png

【问题讨论】:

  • 请做一些研究并花时间发布一个问题,而不是一个指向显示文本的图片的链接。
  • 你为什么决定发布图片而不是文字?
  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:How to create a Minimal, Complete, and Verifiable example
  • @Pshemo 至少他没有将powerpoint文件与源代码的图片链接:-)

标签: java eclipse


【解决方案1】:

你调用了没有参数的程序并且你试图读取一个空的参数数组。

【讨论】:

  • 感谢您的帮助,我该如何更改? :) 我对此很陌生,很抱歉打扰。
  • 谢谢!它成功了。 :)
猜你喜欢
  • 1970-01-01
  • 2013-02-14
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
  • 2014-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多