IDE为Eclipse,src目录下有resource/images文件夹,images里面有一些图片,
现在问题是:我用
new ImageIcon(getClass().getResource("resource/images/a.jpg"));
new ImageIcon("resource/images/a.jpg");
这两种类型都加载不了图片a.jpg,g.drawImage()没有效果啊。可是,用new ImageIcon(getClass().getResource("resource/images/tetris.png"));
却能够加载tetris.png图片,而换new ImageIcon("resource/images/tetris.png");却又不能了。结论是只能加载tetris.png这一张PNG图,我都搞崩溃了!!!!

解决方案 »

  1.   

    试试
    Project > Properties > Java Build Path > Libraries > Add Class Folder > srcgetClass().getResource() 在CLASSPATH中寻找资源
      

  2.   

    用getClass().getClassLoader.getResource("resource/images/tetris.png")试试
      

  3.   

    换用这种方式试试:getClass().getResourceAsStream("resource/images/tetris.png")?
      

  4.   

    这么写,不好使你来找我:
    new ImageIcon(getClass().getResource("/resource/images/a.jpg"));
      

  5.   

    The resource name is constructed from the given resource name using this algorithm: If the name begins with a '/' ('\u002f'), then the absolute name of the resource is the portion of the name following the '/'. 
    Otherwise, the absolute name is of the following form: 
       modified_package_name/name
     Where the modified_package_name is the package name of this object with '/' substituted for '.' ('\u002e').
      

  6.   

    不知道为什么你找不到,我看我这个程序里面都是用的
    new ImageIcon(getClass().getResource(imageURL))
    来找图片,没有说一个找不到的,不过我的图片都是gif的,你换成gif是下看能不能出来