2 Replies Latest reply: Mar 23, 2007 10:35 PM by 807606 RSS

    URL

    807606
      //why my image doesnt show any image when I try to run it in my web server but it just work fine as a desktop application.

      try
      {
      img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("image\\img.jpg"), "image\\img.jpg"));

      }
      catch(Exception e){}
      //this code work fine only when I run my program in desktop but when I try to put this in my webserver it will not get any image.

      Any help pls..

      Stan
        • 1. Re: URL
          807606
          Any help pls..
          Don't do catch(Exception e){}. It may be that with all that I/O going on something
          nasty is happening which leaves img with a strange value. Instead
          try
          {
              // do stuff
          }
          catch(Exception e)
          {
              e.printStackTrace();
          }
          Then you can check the output. You should use System.out.prinln() - or some other
          method - to check the value of img. The most likely reason you don't see an image is
          that img is null. And the most likely reason for that is that the image file doesn't exist,
          or is not accessible to your program for some reason. At any rate these are the
          things I would check first.

          [Edit] Also break up the line you use to assign a value to img. Verify that the
          URL you are using is the one you intend to use.
          • 2. Re: URL
            807606
            You don't need the URL constructor call in there - getResource already returns a URL.