如上,我总是得到空值,哪位高手帮我讲一下? 我要得到本地的地址, 如hello/myPicture.jpg,那么hello/myPicture.jpg应该放到什么地方???

解决方案 »

  1.   

    奇怪的问题
    一直是用Class的getClassLoader().getResource("")来加载文件的,没遇到过这样的问题
      

  2.   

    我是用jigloo才发现这个问题的,我为控件添加图标(如按扭的图片),它帮我把代码生成好了,就是getClassLoader().getResource("")这种形式,然而运行时却产生异常
      

  3.   

    贴一段文档你看看:
    Returns the class loader for the class. Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class was loaded by the bootstrap class loader. 
    If a security manager is present, and the caller's class loader is not null and the caller's class loader is not the same as or an ancestor of the class loader for the class whose class loader is requested, then this method calls the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to ensure it's ok to access the class loader for the class. If this object represents a primitive type or void, null is returned. 
      

  4.   

    中文的:
    getClassLoader
    public ClassLoader getClassLoader()返回该类的类加载器。有些实现可能使用 null 来表示引导类加载器。如果该类由引导类加载器加载,则此方法在这类实现中将返回 null。 
    如果存在安全管理器,并且调用者的类加载器不是 null,也不同于或是请求其类加载器的类的类加载器的祖先,则此方法通过 RuntimePermission("getClassLoader") 权限调用此安全管理器的 checkPermission 方法,以确保可以访问该类的类加载器。 如果此对象表示一个基本类型或 void,则返回 null。 
    返回:
    加载此对象所表示的类或接口的类加载器。 
    抛出: 
    SecurityException - 如果存在安全管理器,并且 checkPermission 方法拒绝对该类类加载器的访问。
    另请参见:
    ClassLoader, SecurityManager.checkPermission(java.security.Permission), RuntimePermission
    的确是存在null的情况。
      

  5.   

    受教了,不过 getClassLoader()并不返回空啊,而是调用了getResource()才返回了null
      

  6.   

    getResource()是用相对路径吗?如果是,它是相对于什么的路径,相对于.class文件的路径?
      

  7.   

    谢谢,这是相对于.class文件的路径还是.java的路径?
      

  8.   

    是class,你可以把资源文件和class打包到一个jar里面。
    如果用eclipse的话把资源文件和java文件放在一起应该能自动编译过去。
      

  9.   

    晕了,勿论如何都得到null, 难道是这样:the invoker doesn't have adequate  privileges to get the resource?
      

  10.   

    应该不是。
    我用applet,把资源打包和类文件打包到jar中都没问题。