Reading image url from a different package.

When I'm trying to read image from a jar with a package structure different from the reading class, the getResource(<image name>) returns the url as null.
For ex: Say I have hello.gif in a jar under
client/resources and also the ResourceHandler in a different package
say client/utils it does not work.
Code for ResourceHandler is as follows:
public class ResourceHandler
public ImageIcon getImage(String imageName)
URL url = this.getClass().getResource(imageName);
System.out.println("-- url retrieved "+url);
return new ImageIcon(url);
The url printed is null. But if I have the ResourceHandler in the package client/resources it works. I believe that the class loader tries to load it from the path relative to this class. Any idea why this behaviour. I would also like to know why just being in the classpath is not sufficient.
--Jos Francis                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

It needs it because the location of resources (like an image) is independent of that of the java code (resources are not .class files).
To look for resources strictly from the syst classpath, you can use the methods getSystemResource() and getSystemResources() . These methods use the system ClassLoader to locate resources.

Similar Messages

  • Automator Stops Responding while trying to perform "Get Image URLs from Webpage"

    I have seen it in many tutorials, and it seems strait forward enough, so here is my order of events for my scriptl;
    Get Current Webpage from Safari
    Get Image URLs from Webpage [linked from these webpages]
    Download URLs [Downloads]
    However when I run this script it returns the get current webpage quickly but then hangs on Get Image URLs from webpage either never passes or takes 700+ seconds to move to the next step.
    The times it did pass to the next step it worked 98% still missed images occasionaly.
    After I figure out how to fix this issue, I am looking for a way to make it create a new folder, and name it according to the sub directory of the webpage, for example:
    http:\\www.mypictures.com\Birthday\01.JPG
    http:\\www.mypictures.com\Birthday\02.JPG
    would create folder Birthday, and save images 1 and 2
    Then in the future I want to download another set such as;
    http:\\www.mypictures.com\MothersDay\01.JPG
    http:\\www.mypictures.com\MothersDay\02.JPG
    As these are both named 01.JPG the sets would overwrite, or add strange numbers and not divide by set by default;
    So I need this script to create folders based on Directory (portion of url)  In my example it would be MothersDay, and Birthday folders.
    Any help would be greatly appreciated!
    Thanks in advance!
                    Mike

    I should add, it has simply frozen and stopped responding about 95% of the 20 times or so I have run it. I have tried rebooting (not sure if that helps on Mac, I'm still new to the OS been a windows user for a long time but so far I love my Mac).

  • Read image direct from file server

    hello, need to help me somebody.
    A like to create form , what read image direct from file server, without store in database.
    Please help me.

    Hi you may go through the below post to find what could be a better way to do that.
    http://forum.java.sun.com/thread.jspa?threadID=5163829
    REGARDS,
    RaHuL

  • Using the file protocol to read a URL from a DataSocket Link (DSL) file

    Hey people,
    The text of the message subject is almost directly lifted from the
    LabVIEW help file. I'm currently a DataSocket server for communication
    between a laptop and a Compact FieldPoint unit. My application is
    currently functioning, but I'm searching for a way to easily change the
    IP of the server without having to recompile the VI into a startup.exe
    file.
    The help file says it is possible to create a file (.dsl extension)
    which contains the URL of the server, with the following format:-
    [InternetShortcut]
    URL=dstp://servername.com/tag
    I have created such a file, but the help file refers to reading the URL
    from the DSL file directly, which I'm not sure how to do. The examples
    use hard-coded strings as their reference URLs, so no help there, and
    as far as I can see the question has not been raised before on these
    boards.
    I am aware that I could probably use the File Open vis and manually
    read the information contained within the file, but then it wouldn't
    make sense to rename it to .dsl or to have any other text other than
    the URL contained within.
    Thanks for your replies.

    Hey Lost And Found,
    There is actually a great example on using .dsl files with DataSocket.  You can append "file:" to the beginning of the path of your .dsl file, and wire it directly into the "connection in" pin of the DS Read.  Check out the example here: http://digital.ni.com/public.nsf/websearch/FCC19AF27EFED9A5862569A500709C58?OpenDocument.  I think that it will provide everything you need and if not, just ask.
    Hope this helps!
    Megan B.
    National Instruments

  • How use PHP to read image files from a folder and display them in Flex 3 tilelist.

    Hello. I need help on displaying images from a folder dynamically using PHP and display it on FLEX 3 TileList. Im currently able to read the image files from the folder but i don't know how to display them in the TileList. This is my current code
    PHP :
    PHP Code:
    <?php
    //Open images directory
    $imglist = '';
    $dir = dir("C:\Documents and Settings\april09mpsip\My Documents\Flex Builder 3\PHPTEST\src\Assets\images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "filename: " . $file . "\n";
    $dir->close();
    ?>
    FLEX 3 :
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="pic.send();">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.rpc.events.ResultEvent;
    public var image:Object;
    private function resultHandler(event:ResultEvent):void
    image = (event.result);
    ta1.text = String(event.result);
    private function faultHandler(event:FaultEvent):void
    ta1.text = "Fault Response from HTTPService call:\n ";
    ]]>
    </mx:Script>
    <mx:TileList x="31" y="22" initialize="init();" dataProvider = "{image}" width="630" height="149"/>
    <mx:String id="phpPicture">http://localhost/php/Picture.php</mx:String>
    <mx:HTTPService id="pic" url="{phpPicture}" method="POST"
    result="{resultHandler(event)}" fault="{faultHandler(event)}"/>
    <mx:TextArea x="136" y="325" width="182" height="221" id="ta1" editable="false"/>
    <mx:Label x="136" y="297" text="List of files in the folder" width="182" height="20" fontWeight="bold" fontSize="13"/>
    </mx:Application>
    Thanks. Need help as soon as possbile. URGENT.

    i have made some changes, in the php part too, and following is the resulting code( i tried it, and found that it works.):
    PHP Code:
    <?php
    echo '<?xml version="1.0" encoding="utf-8"?>';
    ?>
    <root>
    <images>
    <?php
    //Open images directory
    $dir = dir("images");
    //List files in images directory
    while (($file = $dir->read()) !== false)
    if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
    echo "<image>" . $file . "</image>"; // i expect you to use the relative path in $dir, not C:\..........
    //$dir->close();
    ?>
    </images>
    </root>
    Flex Code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="callPHP();">
    <mx:Script>
    <![CDATA[
    import mx.rpc.http.HTTPService;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import mx.rpc.events.FaultEvent;
    import mx.events.ItemClickEvent;
    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    [Bindable]
    private var arr:ArrayCollection = new ArrayCollection();
    private function callPHP():void
    var hs:HTTPService = new HTTPService();
    hs.url = 'Picture.php';
    hs.addEventListener( ResultEvent.RESULT, resultHandler );
    hs.addEventListener( FaultEvent.FAULT, faultHandler )
    hs.send();
    private function resultHandler( event:ResultEvent ):void
    arr = event.result.root.images.image as ArrayCollection;
    private function faultHandler( event:FaultEvent ):void
    Alert.show( "Fault Response from HTTPService call:\n " );
    ]]>
    </mx:Script>
    <mx:TileList id="tilelist"
    dataProvider="{arr}">
    <mx:itemRenderer>
    <mx:Component>
    <mx:Image source="images/{data}" />
    </mx:Component>
    </mx:itemRenderer>
    </mx:TileList>
    </mx:Application>

  • How to instantiate a class from a different package?

    I am trying to instatiate a class in a package: a.b.c from another class in a different package: d.e.f
    How could I do so?
    I've already been trying many things but didn't manage to get it to work...

    Did you include both jar files in your classpath? Use
    the -cp option of the java interpreter to specify your
    classpath.Well, I tried adding the jar file to the classpath, without any success...
    String path = getClass().getProtectionDomain().getCodeSource().getLocation().toString();
                   String finpath = "";
                   for(int i=6;i<path.length();i++)
                        finpath = finpath+path.charAt(i);
                   System.setProperty("java.class.path",System.getProperty("java.class.path")+";"+finpath+"mm.mysql-2.0.14-bin.jar/");That's what I did and it didn't work...
    If you "unpack" the jars see if there is the correct
    packages-folders symmetry...Yes, the classes are in the package-folders they should be in..

  • Child package cannot read param value from parent ssis package

    Hi all,
    I think I must be crazy !! i have a big problem in my ssis project .
    i have more than 40 package one parent and 39 childs 
    i use configuration method to get variable values from parent to child packages and it work well .. but when i copy my ssis project
    to the production server i face the following problem .. childs package didn't read the variables values from the parent package 
    i revised the configuration many times i can't find any missing !!
    any help please ...
    Thanks,

    Do not copy the packages from the projet to the production server, but you must generate the manifest installation including your configuration, and deploy them.
    Note : not forget to include the configuration.
    To learn more about how to install the package :
    Lesson 1:
    http://msdn.microsoft.com/en-us/library/ms365332(v=sql.105).aspx
    Lesson 2 :
    http://msdn.microsoft.com/en-us/library/ms365329(v=sql.105).aspx
    Lesson 3 :
    http://msdn.microsoft.com/en-us/library/ms365321(v=sql.105).aspx

  • Image URL from publishing Image Site column ?

    Hi techies,
    I have created one column say PublishingImage of PublishingImage
    Type and added it in custom list.
    Used this column to upload image. But not able to fetch its URL.
    Used the below line to fetch the Url:
    SPFieldUrlValue oUrl = new SPFieldUrlValue(Convert.ToString(item["PublishingImage"]));
    and assigned the oUrl to Datarow like this:
    dr["Image"] =oUrl.Url;
    but still not getting the proper URL.
    Any help will be appreciated

    Find the similar post
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/bafb60d5-38a3-4985-a10f-46ceca576cdb/how-can-i-read-publishing-image-url-field-programmatically
    ImageFieldValue _field = Item[FieldId.PublishingPageImage] as ImageFieldValue
    Now you can access the properties of the field using this object i.e.
    _field.ImageUrl
    will give you the url stored.

  • How to reference background image url from css?

    Hello,
    I have uploaded some images and css files to the "Shared Components > Images".
    How can I reference my images as "background-image:url('XXX.gif')" for a css element?
    Thanks,
    John

    To make what Tyler said explicit: APEX doesn't perform recursive (or indeed any) substitution on static files, Re: Use uploaded images in uploaded CSS, so images in static files can't be referenced using #APPLICATION_IMAGES# or #WORKSPACE_IMAGES# in style sheets that are themselves static files. The Re: Help with STATIC HTML file reference another STATIC HTML/CSS file..

  • Looking for a script that get images' urls from a website

    Hi,
    I have a website where users can insert theirs hotel informations.
    Most of them do not insert photos, I guess because the procedure is quite long and difficoult for the average user's skills.
    I'm looking for a script that take as input the url of the website and give as output the urls of the images of the site, so the user can decide which to upload on his tab.
    Someone can help me?

    La_Salamandra wrote:
    I have a website where users can insert theirs hotel informations.
    Most of them do not insert photos, I guess because the procedure is quite long and difficoult for the average user's skills.
    I'm looking for a script that take as input the url of the website and give as output the urls of the images of the site, so the user can decide which to upload on his tab.
    Someone can help me?
    You have to improve your design. Even if you can find the Coldfusion code, your design will still fall short in 2 ways.
    First, it is unreliable, because you're depending on some arbitrary site to be available and up to speed. Secondly, it is aesthetically wrong to be collecting pictures, especially large numbers of them, dynamically from someone else's site.  Think of their copyright and bandwidth.
    Fortunately, there are simple solutions. First, identify, by eye, the web pages containing the pictures you're interested in. Ask for permission from the owner.
    You could indeed use Coldfusion's cfhttp or any other script to download the JPGs, PNGs, and so on. But then, why waste your time re-inventing the wheel? It is infinitely better to use a web crawler !
    With most crawlers, you only have to supply the URL of the site, and the file extensions it has to grab (in your case, jpg, png, bmp, and so on).
    One click on the button, and you have them reeling in. Automatically. Some crawlers are considerate enough to enable you to adjust the download bandwidth. (We can learn from a million years evolution wisdom. The vampire bat is known to inject a painkiller before sucking!).
    Now that you've downloaded the images to your site, the links you display to your users are all yours. You may choose to resize some of the images, display them as you wish, and the issues of reliability and bandwidth are now up to you.

  • Get current URL from PL/SQL Package in Portal

    Hello, anyone knows the magic code to get the URL of current Web page from a package running from inside the same page?
    Thx

    You can use the page_url field of the portlet runtime record.

  • I'm trying to listen to a track on youtube, whilst reading the lyrics from a different link. as soon as i click the next link, the youtube shuts off. please help

    How do I listen to a track on youtube, whilst accessing a different link for the lyrics? each time I try, the music stops as soon as i clic the next link. this never happens on MS Explorer

    Hi ..
    Flash is required for most YouTube content. 
    From your Safari menu bar click Safari > Preferences then select the Privacy tab.
    Click:  Remove All Website Data
    Then delete the cache.
    Open a Finder window. From the Finder menu bar click Go > Go to Folder
    Type or copy paste the following
    ~/Library/Caches/com.apple.Safari/Cache.db
    Click Go then move the Cache.db file to the Trash.
    Now open System Preferences > Flash Player then select the Advanced tab.
    Click:  Delete All under Browsing Data and Settings
    Quit and relaunch Safari to test.
    If that doesn't help, go back to System Preferences > Flash Player > Advanced then click Check Now. There may be a Flash update available.

  • Read image data from SQL Server database and display it in a JSP web page

    Hi experts,
    I am doing a project in which I have to upload images to the database via JSP/servlets. I am able to do this.
    Now I want users to view and dowload these images which are stored in the database.
    Please help me of how can I read the images from the database and display it on jsp webpage and also can be downloaded by users via jsp pages on client side.
    Please help!

    Hi you may go through the below post to find what could be a better way to do that.
    http://forum.java.sun.com/thread.jspa?threadID=5163829
    REGARDS,
    RaHuL

  • How to read Image data from oracle DB?

    How to read a oracle database object ORDSYS.ORDImage from oracle
    database?
    I can get a oracle.sql.STRUCT object from the database, but i can not
    find the way to convert data to a image object(like oracle.ord.im.OrdImage)
    I had used "OrdImage imgObjj1 =
    (OrdImage)rs.getCustomDatum(1, OrdImage.getFactory());"
    it's a example from oralce.
    But OracleResultSet.getCustomDatum() method is already deprecated,
    i can't find a new method to instead of it.
    Who can help me ? Thank you!
    [email protected]

    More than likely, this is the interface you will use:
    java.sql.Blob
    http://java.sun.com/j2se/1.4/docs/api/java/sql/Blob.html
    Once you get the blob, construct a Raster objects from the Bytes you receive from the blob. Then you can create an Image, ImageIcon, BufferedImage, whatever with the Raster object.
    Good luck!

  • Read Image file from BLOB.

    Hi All,
    I am trying to load data from BLOB data from database and save the image file.
    SQL to insert data:
    INSERT INTO BLOBTest (BLOBName, BLOBData)
    SELECT 'First test file', BulkColumn FROM OPENROWSET(Bulk 'C:\Inbound\logo.jpg', SINGLE_BLOB) AS BLOB
    I am using the following 'SELECT top 1 BLOBData from BLOBTest' to get the data and setting the value to 'Image Saver' action. The image file is saved to the specified path, but the image is not opening.
    I get "Image is damaged, corrupted or is too large message. The file is around 40 KB."
    Am i missing something.
    Any help would be highly appreciated.
    MII Version: 14.0 SP 3
    Thanks,

    I think this thread might help: Can we interpret Oracle BLOB data in SAP MII and how?
    Basically MII doesn't support the BLOB/CLOB data types so in your query you will need to convert it to a base64 string that MII can consume using the image saver action.
    Regards,
    Christian

Maybe you are looking for