• Post Reply Bookmark Topic Watch Topic
  • New Topic

ImageIcon problem  RSS feed

 
Vidya Venkatesh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi I'm facing a problem with ImageIcon. In my applet, I'm trying to read images from a zip file on the server. The image objects are read and created correctly, but the ImageIcon objects which I make from the Image objects are null. The interesting part is that this is happening only when I run the applet from my office computer. When I run it from home, the ImageIcon objects are not null and displayed correctly. The code is shown below. Please advise.
Thank you
Vidya
public static Hashtable getImageTableFromZip(String zipFileName)
{
Hashtable imageTable=new Hashtable();
ZipInputStream zipIn;
try
{
String zipFilePath=Environment.getInstance().getImageZipUrl ();
URL url = new URL(zipFilePath+zipFileName);
InputStream in = url.openConnection().getInputStream();
BufferedInputStream bufIn = new BufferedInputStream(in);
zipIn = new ZipInputStream(bufIn);
ZipEntry zipEntry;
while((zipEntry = zipIn.getNextEntry()) != null)
{
Image image=extractImageFromZip(zipIn);
ImageIcon imageIcon=new ImageIcon(image);
System.out.println ("image is "+image +" imageicon made from image is "+imageIcon);
imageTable.put(zipEntry.getName(),imageIcon);
}

}catch(Exception e){e.printStackTrace(); }
return imageTable;
}
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code that I see looks OK... maybe it's a problem with the computer at work accessing the internet through a proxy? Then the applet wouldn't be able to access the zip file...

 
Vidya Venkatesh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Thanks for the reply. But if it was a problem with the proxy, then the Image object would also have been null, right ? Here the Image object is created properly, but the ImageIcon is null. Why would the ImageIcon object be null inspite of creating it by saying ImageIcon icon=new ImageIcon(image);
// where image is a Image object
Thank You
Vidya
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, that's right... I also went back and tested out reading from a zip file locally and trying to read from a zipfile that doesn't exist throws a java.util.ZipException, so that would probably happen if the applet couldn't find the zip file due to a proxy problem, too...

If you override a component to paint the image in its paintComponent() method, do you see the image?

The only other thing I can think of is, is the Java installation on your computer at work different than the one at home? Perhaps there is an older version of ImageIcon on your computer at work that has a bad implementation... though I've never heard of this before... also, I've never heard of a constructor returning null... are any exceptions being thrown, caught, and ignored? (ie.)
 
indian greenhorn
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vidya Venkatesh:
hi I'm facing a problem with ImageIcon. In my applet, I'm trying to read images from a zip file on the server. The image objects are read and created correctly, but the ImageIcon objects which I make from the Image objects are null. The interesting part is that this is happening only when I run the applet from my office computer. When I run it from home, the ImageIcon objects are not null and displayed correctly. The code is shown below. Please advise.
Thank you
Vidya
public static Hashtable getImageTableFromZip(String zipFileName)
{
Hashtable imageTable=new Hashtable();
ZipInputStream zipIn;
try
{
String zipFilePath=Environment.getInstance().getImageZipUrl ();
URL url = new URL(zipFilePath+zipFileName);
InputStream in = url.openConnection().getInputStream();
BufferedInputStream bufIn = new BufferedInputStream(in);
zipIn = new ZipInputStream(bufIn);
ZipEntry zipEntry;
while((zipEntry = zipIn.getNextEntry()) != null)
{
Image image=extractImageFromZip(zipIn);
ImageIcon imageIcon=new ImageIcon(image);
System.out.println ("image is "+image +" imageicon made from image is "+imageIcon);
imageTable.put(zipEntry.getName(),imageIcon);
}

}catch(Exception e){e.printStackTrace(); }
return imageTable;
}
 
indian greenhorn
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vidya Venkatesh:
hi I'm facing a problem with ImageIcon. In my applet, I'm trying to read images from a zip file on the server. The image objects are read and created correctly, but the ImageIcon objects which I make from the Image objects are null. The interesting part is that this is happening only when I run the applet from my office computer. When I run it from home, the ImageIcon objects are not null and displayed correctly. The code is shown below. Please advise.
Thank you
Vidya
public static Hashtable getImageTableFromZip(String zipFileName)
{
Hashtable imageTable=new Hashtable();
ZipInputStream zipIn;
try
{
String zipFilePath=Environment.getInstance().getImageZipUrl ();
URL url = new URL(zipFilePath+zipFileName);
InputStream in = url.openConnection().getInputStream();
BufferedInputStream bufIn = new BufferedInputStream(in);
zipIn = new ZipInputStream(bufIn);
ZipEntry zipEntry;
while((zipEntry = zipIn.getNextEntry()) != null)
{
Image image=extractImageFromZip(zipIn);
ImageIcon imageIcon=new ImageIcon(image);
System.out.println ("image is "+image +" imageicon made from image is "+imageIcon);
imageTable.put(zipEntry.getName(),imageIcon);
}

}catch(Exception e){e.printStackTrace(); }
return imageTable;
}


Hello, one idea is to try a sample (small) code with an imageicon class in that and see whether it is working fine. If it is fine certainly there is something wrong in the code. If it is not so certainly it is the problem of the system.
regards,
Krishna
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!