Results 1 to 11 of 11
  1. #1
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default ClassLoader.getSystemResource() returns null

    Hi,

    as mentioned in the title:
    Java Code:
    URL iconURL = ClassLoader.getSystemResource("img/bird.gif");
    when I use this, iconURL returns null.

    I have a folder img in my project where bird.gif is in.

    Can someone help my with this issue please?

    Regards
    Sven
    Last edited by SVENeRGy; 01-07-2012 at 02:31 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,570
    Rep Power
    25

    Default Re: ClassLoader.getSystemResource() returns null

    Is the folder that contains the img folder on the classpath?
    Last edited by Norm; 01-07-2012 at 02:38 PM. Reason: added contains

  3. #3
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: ClassLoader.getSystemResource() returns null

    Hi,
    thanks for answering so fast.

    it is added as class folder in libraries. I hope this is correct.

    This doesn't do the trick

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,570
    Rep Power
    25

    Default Re: ClassLoader.getSystemResource() returns null

    What folders are on your classpath? Is the folder containing the img folder on the classpath when you execute your program?

  5. #5
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: ClassLoader.getSystemResource() returns null

    folder img
    and system library

  6. #6
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: ClassLoader.getSystemResource() returns null

    added the images to a jar file, and added the jar file to the libraries. Now it works.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,570
    Rep Power
    25

    Default Re: ClassLoader.getSystemResource() returns null

    You're not answering the question about what folders are on the classpath.
    Get the System Properties and display them to show the classpath's contents.

  8. #8
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: ClassLoader.getSystemResource() returns null

    I hope this is what you have been asking for.

    java.class.path now = /Users/sven/Documents/workspace/Boek2Hoofdstuk03/bin:/Users/sven/Documents/workspace/Boek2Hoofdstuk03/img

    regards
    Sven

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,570
    Rep Power
    25

    Default Re: ClassLoader.getSystemResource() returns null

    The folder containing the img folder should be on the classpath:
    the classpath + the path in the call to getSystemResource() should be the full path to the resource.
    The way you have it would be like this with two img folders:
    /Users/sven/Documents/workspace/Boek2Hoofdstuk03/img/img/bird.gif

  10. #10
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: ClassLoader.getSystemResource() returns null

    {java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries, java.vm.version=20.4-b02-402, awt.nativeDoubleBuffering=true, gopherProxySet=false, mrj.build=11M3527, java.vm.vendor=Apple Inc., java.vendor.url=http://www.apple.com/, path.separator=:, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, sun.java.launcher=SUN_STANDARD, user.country=NL, sun.os.patch.level=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/Users/svendobbels/Documents/workspace/Boek2Hoofdstuk03, java.runtime.version=1.6.0_29-b11-402-11M3527, java.awt.graphicsenv=apple.awt.CGraphicsEnvironmen t, java.endorsed.dirs=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/endorsed, os.arch=x86_64, java.io.tmpdir=/var/folders/0y/d9znkpt160x6l_j9lwtjc1pr0000gn/T/, line.separator=
    , java.vm.specification.vendor=Sun Microsystems Inc., os.name=Mac OS X, sun.jnu.encoding=MacRoman, java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java, java.specification.name=Java Platform API Specification, java.class.version=50.0, sun.management.compiler=HotSpot 64-Bit Tiered Compilers, os.version=10.7.2, http.nonProxyHosts=local|*.local|169.254/16|*.169.254/16, user.home=/Users/svendobbels, user.timezone=, java.awt.printerjob=apple.awt.CPrinterJob, file.encoding=MacRoman, java.specification.version=1.6, java.class.path=/Users/svendobbels/Documents/workspace/Boek2Hoofdstuk03/bin:/Users/svendobbels/Documents/workspace/Boek2Hoofdstuk03/img, user.name=svendobbels, java.vm.specification.version=1.0, sun.java.command=sven.dobbels.SwingUtils.GetClassP ath, java.home=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home, sun.arch.data.model=64, user.language=nl, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=apple.awt.CToolkit, java.vm.info=mixed mode, java.version=1.6.0_29, java.ext.dirs=/Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/lib/ext, sun.boot.class.path=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsfd.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/Resources/Java/JavaRuntimeSupport.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/ui.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/laf.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/sunrsasign.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jsse.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/jce.jar:/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/charsets.jar, java.vendor=Apple Inc., file.separator=/, java.vendor.url.bug=http://bugreport.apple.com/, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, mrj.version=1070.1.6.0_29-402, socksNonProxyHosts=local|*.local|169.254/16|*.169.254/16, ftp.nonProxyHosts=local|*.local|169.254/16|*.169.254/16, sun.cpu.isalist=}

  11. #11
    SVENeRGy is offline Member
    Join Date
    Jan 2012
    Posts
    7
    Rep Power
    0

    Default Re: ClassLoader.getSystemResource() returns null

    sorry for previous post.

    works now, just had to put an img folder in my img folder.
    tnx

Similar Threads

  1. ArrayList returns null
    By aborgeld in forum New To Java
    Replies: 6
    Last Post: 04-01-2011, 01:32 PM
  2. XML and SAX - class returns 'null'
    By Laffel in forum Advanced Java
    Replies: 2
    Last Post: 03-07-2011, 09:14 PM
  3. Splashscreen returns null
    By Charlie161 in forum AWT / Swing
    Replies: 2
    Last Post: 03-04-2011, 01:25 PM
  4. getImplementationVersion() returns null
    By newbiejava in forum New To Java
    Replies: 22
    Last Post: 09-12-2010, 09:31 AM
  5. helpset findHelpSet returns null
    By kmm1977 in forum AWT / Swing
    Replies: 23
    Last Post: 06-22-2010, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •