Problema de imagem com applets

4 respostas
K

boas, estou aqui com um problema numa applet, nao consegue encontrar as imagens :S

aqui esta a linha de codigo:

1. private static Image pieceImage[][] = new Image[2][6];  
   2.     private static String imageFilename[][] = {  
   3.         { "wp.gif", "wn.gif", "wb.gif", "wr.gif", "wq.gif", "wk.gif" },  
   4.         { "bp.gif", "bn.gif", "bb.gif", "br.gif", "bq.gif", "bk.gif" }};  
   5.           
   6.     public static void bufferImages(Applet app) {  
   7.         for (int i = 0; i < 2; i++)  
   8.             for (int j = 0; j < 6; j++)  
   9.                 pieceImage[i][j] = app.getImage(app.getClass().getResource("/images/" + imageFilename[i][j]));  
  10.     }  
  11.

e aqui a imagem com a pasta(dentro dessa pasta encontra.se as imagens)


4 Respostas

B

Tem alguma imagem dentro da pasta images?

K

tenho as imagens todas das peças de xadrez.

private static String imageFilename[][] = { { "wp.gif", "wn.gif", "wb.gif", "wr.gif", "wq.gif", "wk.gif" }, { "bp.gif", "bn.gif", "bb.gif", "br.gif", "bq.gif", "bk.gif" }};


B

Provavelmente /images/ está apontando p/ a raiz do drive, em c:\images.

Talvez de trocar /images/ por images/, ele pegue o endereço relativo a partir de onde o programa está rodando.

K

igual…

java.lang.NullPointerException

at sun.awt.image.URLImageSource.(Unknown Source)

at sun.applet.AppletImageRef.reconstitute(Unknown Source)

at sun.misc.Ref.get(Unknown Source)

at sun.applet.AppletViewer.getCachedImage(Unknown Source)

at sun.applet.AppletViewer.getImage(Unknown Source)

at java.applet.Applet.getImage(Unknown Source)

at ChessApp.BoardView.bufferImages(BoardView.java:292)

at ChessApp.ChessApp.init(ChessApp.java:27)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)
Criado 10 de setembro de 2008
Ultima resposta 10 de set. de 2008
Respostas 4
Participantes 2