java.lang.ExceptionInInitializerError,请解释

时间:2014-01-16 01:44:29

标签: javascript eclipse runtime-error lwjgl

此错误:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.PoseidonTechnologies.caveworld.level.WoRe.<init>(WoRe.java:46)
    at com.PoseidonTechnologies.caveworld.CaveWorld.start(CaveWorld.java:80)
    at com.PoseidonTechnologies.caveworld.CaveWorld.main(CaveWorld.java:303)
Caused by: java.lang.RuntimeException: !!
    at com.PoseidonTechnologies.caveworld.Tea.loT(Tea.java:61)
    at com.PoseidonTechnologies.caveworld.level.Ch.<clinit>(Ch.java:20)
    ... 3 more

这是导致此错误的代码区域:

  @SuppressWarnings({ "unchecked", "rawtypes" })
private static HashMap<String, Integer> iM = new HashMap();
  private static int lId = -9999999;

  public static int loT(String path, int m) {
      File file = new File(path);
    try {
      if (iM.containsKey(file)) {
        return ((Integer)iM.get(file)).intValue();
      }
      IntBuffer ib = BufferUtils.createIntBuffer(1);

      GL11.glGenTextures(ib);
      int id = ib.get(0);

      bind(id);

      GL11.glTexParameteri(3553, 10241, m);
      GL11.glTexParameteri(3553, 10240, m);

      BufferedImage bi = ImageIO.read(file);
      int w = bi.getWidth();
      int h = bi.getHeight();

      ByteBuffer ppi = BufferUtils.createByteBuffer(w * h * 4);
      int[] rPs = new int[w * h];
      bi.getRGB(0, 0, w, h, rPs, 0, w);
      for (int i = 0; i < rPs.length; i++)
      {
        int a = rPs[i] >> 24 & 0xFF;
        int r = rPs[i] >> 16 & 0xFF;
        int g = rPs[i] >> 8 & 0xFF;
        int b = rPs[i] & 0xFF;

        rPs[i] = (a << 24 | b << 16 | g << 8 | r);
      }
      ppi.asIntBuffer().put(rPs);
      GLU.gluBuild2DMipmaps(3553, 6408, w, h, 6408, 5121, ppi);

      return id;
    }
    catch (IOException e)
    {
      throw new RuntimeException("!!");
    }
  }

更具体地说,这些确切的行;

catch (IOException e)
{
  throw new RuntimeException("!!");
}

我已经尝试删除throw new RuntimeException但是Eclipse告诉我public static loT需要一个return语句,虽然当我在我的类文件中保留这行代码时,我不断收到此错误,我的程序将崩溃。

我在Eclipse中使用LWJGL。这个类正在尝试加载要分配给某些东西的纹理文件。

我想知道发生了什么,为什么会发生这种情况,如果有人知道如何解决这个问题,以及是否可以修复它。如果您需要更多信息,或者(由于某种原因)不清楚我在问什么,只需发表评论而不是低估这一点,因为我真的想要解决这个问题。

谢谢!

编辑:对@RobHruska和@dhamibirendra提出使用e.printStackTrace()的原始建议。

以下是更新的错误日志:

javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(Unknown Source)
    at com.PoseidonTechnologies.caveworld.Tea.loT(Tea.java:38)
    at com.PoseidonTechnologies.caveworld.level.Ch.<clinit>(Ch.java:20)
    at com.PoseidonTechnologies.caveworld.level.WoRe.<init>(WoRe.java:46)
    at com.PoseidonTechnologies.caveworld.CaveWorld.start(CaveWorld.java:80)
    at com.PoseidonTechnologies.caveworld.CaveWorld.main(CaveWorld.java:303)
Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.PoseidonTechnologies.caveworld.level.WoRe.<init>(WoRe.java:46)
    at com.PoseidonTechnologies.caveworld.CaveWorld.start(CaveWorld.java:80)
    at com.PoseidonTechnologies.caveworld.CaveWorld.main(CaveWorld.java:303)
Caused by: java.lang.RuntimeException: javax.imageio.IIOException: Can't read input file!
    at com.PoseidonTechnologies.caveworld.Tea.loT(Tea.java:62)
    at com.PoseidonTechnologies.caveworld.level.Ch.<clinit>(Ch.java:20)
    ... 3 more
Caused by: javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(Unknown Source)
    at com.PoseidonTechnologies.caveworld.Tea.loT(Tea.java:38)
    ... 4 more

显然它不是在阅读我的图片文件。

这是请求它的行(我相信):

private void rebuild(int l) {
    if (rTF == 2) {
      return;
    }
    this.m = false;

    u += 1;

    rTF += 1;

    GL11.glNewList(this.l + l, 4864);
    GL11.glEnable(3553);
    GL11.glBindTexture(3553, tex);
    teb.init();
    @SuppressWarnings("unused")
int tiles = 0;
    for (int x = this.x0; x < this.x1; x++) {
      for (int y = this.y0; y < this.y1; y++) {
        for (int z = this.z0; z < this.z1; z++) {
          if (this.wo.isT(x, y, z)) {
            int tex = y == this.wo.d * 2 / 3 ? 0 : 1;
            tiles++;
            if (tex == 0) {
              Ti.stone.render(teb, this.wo, l, x, y, z);
            }else{
              Ti.grass.render(teb, this.wo, l, x, y, z);
            }
          }
        }
      }
    }
    teb.flush();
    GL11.glDisable(3553);
    GL11.glEndList();
  }

int是“tex”,这里是:

private static int tex = Tea.loT("groundtex.png", 9728);

1 个答案:

答案 0 :(得分:0)

您的代码(抛出异常部分)应该正常工作。 ExceptionInInitializer 表示静态初始化中发生了意外异常。

这意味着,你遇到了一些问题 com.PoseidonTechnologies.caveworld.Tea.loT(Tea.java:61)。

检查该行上的内容。你在那里遇到麻烦。尝试:

catch (IOException e)
{
  e.printStackTrace();
  throw new RuntimeException("!!");
}