This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

ImageIcon problem

 
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;
}
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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 Spring Java
  • 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.)
 
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
 
The only cure for that is hours of television radiation. And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic