jar problem and applet on server problem

it is terrible, i want to get my applet work in the net and then
problems, problems, problems…

first one: i tried to load my (in browser working applet) on my
net account. after loading most of the image resources i get.

java.util.zip.ZipException: invalid stored block lengths

i searched inside my code to find the line, where the exception occurs. its


img = ImageIO.read(getClass().getResource("tiles/drehung.png"));

but it is not the first image i load. the image is properly loaded onto the server, the path is also correct.

next one:

i want to get my applet packed in a jar. all is wonderful except that there also a problem that i get an exception:
my applet doesnt seem to load the images correctly in my vector, so a indexoutofbounds exception is thrown when it tries to acces images for painting.
the loading code is the same as above…

java.util.zip.ZipException: invalid stored block lengths

Archive broken? Download and compare it to your local copy (eg with a hexeditor… tools->compare (or so))

img = ImageIO.read(getClass().getResource(“tiles/drehung.png”));

Relative pathes should start with an ‘/’ eg: “/tiles/drehung.png”

Also… disable caching ImageIO.setUseCache(false) otherwise it would need the permission for writing files.

java.util.zip.ZipException: invalid stored block lengths :

im using no archive, no zip, no jar …

Does the exception come from ImageIO.read or getClass().getResource()?

If it is in ImageIO.read then read try reading the data into a bytearray before sending it to ImageIO.

an exception says more than i ever could do:
this is from my try to upload the applet (not packed in a jar) on my server


java.util.zip.ZipException: invalid stored block lengths

      at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:142)

      at java.io.BufferedInputStream.fill(BufferedInputStream.java:186)

      at java.io.BufferedInputStream.read1(BufferedInputStream.java:225)

      at java.io.BufferedInputStream.read(BufferedInputStream.java:283)

      at java.io.DataInputStream.readFully(DataInputStream.java:213)

      at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:1174)

      at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1278)

      at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1364)

      at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1532)

      at javax.imageio.ImageIO.read(ImageIO.java:1317)

      at javax.imageio.ImageIO.read(ImageIO.java:1283)

      at ImageLoader.<init>(ImageLoader.java:69)

      at Memory.init(Memory.java:45)

      at sun.applet.AppletPanel.run(AppletPanel.java:344)

      at java.lang.Thread.run(Thread.java:539)

An image file could not be read: 
javax.imageio.IIOException: Error reading PNG image data

java.lang.IndexOutOfBoundsException: Index: 39, Size: 37

      at java.util.ArrayList.RangeCheck(ArrayList.java:503)

      at java.util.ArrayList.get(ArrayList.java:315)

      at ImageLoader.getStrip(ImageLoader.java:217)

      at HighScoreMenu.<init>(HighScoreMenu.java:20)

      at Memory.init(Memory.java:46)

      at sun.applet.AppletPanel.run(AppletPanel.java:344)

      at java.lang.Thread.run(Thread.java:539)

  • i changed path to have a leading “/”
  • the line “ImageLoader 69” is the image loading line i posted before
  • ImageLoader.getStrip() would only return an animationstrip created on base of the loaded images.
    because it throws an indexoutofboundexception i assume
    that the images arent loaded properly

at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.jav a:1174)

I guess the Images are kinda broken :-X

Check if you can see 'em in your browser.

i was not too lazy and have tested some things:

the applet works fine offline in all my browsers and i have transferred the working files more thatn a few times to my account.

then i wrote a little applet which does nothing more than displaying an image usinf ImageIO read same way i use it in my target-applet. all works fine.
i also tested the images by calling them from the server using
their url. all are displayed correctly.

i have no clue …

The next step is to determine if it’s a bug in ImageIO. Try to load your images the following way ,instead of "img = ImageIO.read(getClass().getResource(“tiles/drehung.png”));
"


byte imageData[] = readFully(getClass().getResourceAsStream("tiles/drehung.png"));
img = ImageIO.read(new ByteArrayInputStream(imageData));


/**
 * Gets the content of the input stream until eof, as a byte array.
 */
public static byte[] readFully(InputStream in) throws IOException {
   ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
   byte buffer[] = new byte[1024];
   int bytesRead = -1;
   while ((bytesRead = in.read(buffer)) != -1) {
         byteOut.write(buffer, 0, bytesRead);
   }
   return byteOut.toByteArray();
}


got the error devil !!

first, thx for your detailed help.
i replaced all images by a png file which is nothing more than a black rectangle.
and it runs …

im not sure, which (or all ?) png is corrupted. but still i cannot explain the error.
all pngs are viewable in the browser as in the applet, but not online …

im not sure, which (or all ?) png is corrupted.

Baaaa stupid me :-X

Well ok… next time you can just check the png files with pngcheck. It’s a little cute command line tool, wich tells you if your png files are valid or not.

ok, still some work to do for ya.

the problem is png in general. if i replace only one random “blue-box”-png by its real graphic ill get the problem. i tested all pngs with your tool: they get validatet without problems.
then i thought of a thing i have forgotten !

this codesnippet should be very familiar to you:


      private void createAnimationStrips(BufferedImage img, int number)
      {
            
            int cellHeight = img.getHeight();
            int cellWidth  = img.getWidth() / number;
            
            GraphicsEnvironment   ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
          GraphicsDevice        gd = ge.getDefaultScreenDevice();
          GraphicsConfiguration gc = gd.getDefaultConfiguration();
            
            for(int i=0; i<number; i++)
            {
                  AnimationStrip anim = new AnimationStrip();
                  
//                  frame = img.getSubimage(i*cellWidth, 0, cellWidth, cellHeight);
                  
                  BufferedImage frame = gc.createCompatibleImage(cellWidth, cellHeight,Transparency.TRANSLUCENT);
                  Graphics2D tg = (Graphics2D)frame.getGraphics();
                  tg.setComposite(AlphaComposite.Src);
                  tg.drawImage(img, 0, 0, cellWidth, cellHeight, i*cellWidth, 0, i*cellWidth+cellWidth, cellHeight, null);

                  anim.add(frame);
                  
                  tg.dispose();
            
                  strips.add(anim);
            }
            
            
      }

the only thing i changed in comparison to your original is that i set the transparency from BITMASK to TRANSLUCENT. reason is that i use png only for file which need transparent background (gif has a lack of colors).

so my conclusion, dear sherlock, the pngs are valid but are not loaded correctly during runtime. so the error has to be within the tile-cutter method…

Are the images translucent (fullalpha)? I’m asking because png supports both (bitmask and fullalpha).

However, that shouldn’t be a problem anyways.

anim.add(frame);

tg.dispose();

Oh and I would change ^their^ order.

And… hmm… can you link one of those images wich trigger the error?

ok, i changed order (but it should be no problem … !?) problem is still there

your link to an image
[link]http://zeus.fh-brandenburg.de/~huellein/button_1plr.png[/link]

Hm… hadn’t found anything. The image looks ok with several viewers, the server allows hotlinking… dunno :l

Well… you can try this image…

It’s about 5kb smaller (used pngout by Ken Silverman ;))

You said it worked locally… have you moved it into a different directory and checked it there? (a place were the images arent available in decompressed state)

its getting more and more odd.
i wrote a very naked applet which references an image two times: one using imageio and one using normal getImage()
both times worked normal using a jpeg.

now i did nothing else than taking a png
heres the source


public class Web extends Applet {
      
      public void init() {
      }

      public void paint(Graphics g) 
      {
            ImageIO.setUseCache(false);
            
            Image img = getImage(getCodeBase(), "a.png");
            URL u = getClass().getResource("/a.png");
            BufferedImage img2;
            
            try
            {
                  img2 = ImageIO.read(u);
            }
            catch(IOException e)
            {
                  System.out.println("Fehler beim Referenzieren des Images");
            }
            
            g.drawImage(img, 0, 0, this);
            g.drawImage(img, 20, 20, this);
      }
}

the images are displayed but console spits several odd exceptions.

please take a look at:
[[link]http://zeus.fh-brandenburg.de/~huellein/web/Web.htm[/link]

the images are displayed

No, not really…

g.drawImage(img, 0, 0, this);
g.drawImage(img, 20, 20, this);

You are drawing the same image twice.

Well, here is the one with ImageIO working:

web2.htm


<html>
<head>
</head>
<body BGCOLOR="000000">
<center>
<applet
      code      ="Web.class"
      archive ="web.jar"
      width      ="500"
      height      ="300"
      >
</applet>
</center>
</body>
</html>

Web.java


import javax.imageio.ImageIO;

public class Web extends Applet
{
      java.awt.image.BufferedImage bufferedimage;
    public Web()
    {
    }

    public void init()
    {
            ImageIO.setUseCache(false);
            java.net.URL url = getClass().getResource("/a.png");

            try
            {
                  System.out.println("ImageIO start");
                  bufferedimage = ImageIO.read(url);
                  System.out.println("ImageIO end");
            }
            catch(IOException ioexception)
            {
                  System.out.println("Fehler beim Referenzieren des Images");
        }
    }

    public void paint(Graphics g)
    {
        g.drawImage(bufferedimage, 20, 20, this);
    }
}

The image is just in the jar. For loading it from outside the jar you need to create the URL with getDocumentBase() + (I think - I’ve never used that).

ahhh dumb mistake … its late in germany, and im tired and tired of dumb exceptions. perhaps tomorrow i will see clearer …

I’ll bet its an ImageIO bug. Don’t read your data using ImageIO. It is buggy. Load your data in first. Then when you have it safe in memory send it to ImageIO using a ByteArrayInputStream. Or use another workaround.

@onxy:

very interesting: your web.-applet works ?!
not for me


Java(TM) Plug-in: Version 1.4.0
Verwendung der JRE-Version 1.4.0-beta3 Java HotSpot(TM) Client VM
Home-Verzeichnis des Benutzers = C:\Dokumente und Einstellungen\Maurice

Proxy-Konfiguration:Proxy-Konfiguration des Browsers





----------------------------------------------------
c:   Konsolenfenster löschen
f:   Objekte in Finalisierungswarteschlange finalisieren
g:   Speicherbereinigung
h:   Diese Hilfemeldung anzeigen
l:   ClassLoader-Liste ausgeben
m:   Speicherbelegung drucken
o:   Protokollieren auslösen
p:   Proxy-Konfiguration neu laden
q:   Konsole ausblenden
r:   Richtlinien-Konfiguration neu laden
s:   Systemeigenschaften ausgeben
t:   Threadliste ausgeben
x:   ClassLoader-Cache löschen
0-5: Trace-Stufe auf <n> setzen
----------------------------------------------------
ImageIO start

javax.imageio.IIOException: Unknown row filter type (= 255)!

      at com.sun.imageio.plugins.png.PNGImageReader.decodePass(PNGImageReader.java:1198)

      at com.sun.imageio.plugins.png.PNGImageReader.decodeImage(PNGImageReader.java:1278)

      at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1364)

      at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1532)

      at javax.imageio.ImageIO.read(ImageIO.java:1317)

      at javax.imageio.ImageIO.read(ImageIO.java:1283)

      at Web.init(Web.java:27)

      at sun.applet.AppletPanel.run(AppletPanel.java:344)

      at java.lang.Thread.run(Thread.java:539)

Fehler beim Referenzieren des Images

java.lang.NullPointerException

      at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:51)

      at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:718)

      at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:150)

      at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2785)

      at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2775)

      at Web.paint(Web.java:38)

      at sun.awt.RepaintArea.paint(RepaintArea.java:177)

      at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:262)

      at java.awt.Component.dispatchEventImpl(Component.java:3587)

      at java.awt.Container.dispatchEventImpl(Container.java:1440)

      at java.awt.Component.dispatchEvent(Component.java:3368)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)

      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:193)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:147)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:141)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:133)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:101)

java.lang.NullPointerException

      at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:51)

      at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:718)

      at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:150)

      at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2785)

      at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2775)

      at Web.paint(Web.java:38)

      at sun.awt.RepaintArea.paint(RepaintArea.java:177)

      at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:262)

      at java.awt.Component.dispatchEventImpl(Component.java:3587)

      at java.awt.Container.dispatchEventImpl(Container.java:1440)

      at java.awt.Component.dispatchEvent(Component.java:3368)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)

      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:193)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:147)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:141)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:133)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:101)

java.lang.NullPointerException

      at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:51)

      at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:718)

      at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:150)

      at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2785)

      at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2775)

      at Web.paint(Web.java:38)

      at sun.awt.RepaintArea.paint(RepaintArea.java:177)

      at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:262)

      at java.awt.Component.dispatchEventImpl(Component.java:3587)

      at java.awt.Container.dispatchEventImpl(Container.java:1440)

      at java.awt.Component.dispatchEvent(Component.java:3368)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)

      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:193)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:147)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:141)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:133)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:101)


perhaps we should try this:
please take on minute and try to load my applet, i have replaced some of the images back to original. if i cant view your applet, perhaps i cant even view mine …

[link]http://zeus.fh-brandenburg.de/~huellein/memory/Memory.htm[/link]

i really have to apologize, so much help and such a dumb reson for the error. i got:
while i pasted the last exception i noticed that im was using
java 1.4.0-beta3. and theres hides the bug-devil.

i could cry if i think about the time i have wasted last days …