Getting error with ImageIO.read(getClass().getResourceAsStream (input==NULL)?

前端 未结 2 1288
情书的邮戳
情书的邮戳 2021-01-29 08:07

I keep getting this error when I use the following code:

try    
{
      image=ImageIO.read(getClass().getResourceAsStream(\"build/classes/javaproject/Space.gif\         


        
相关标签:
2条回答
  • 2021-01-29 08:35

    I am assuming, from the name, that build/classes/ is a folder on your classpath; so what you probably need to write is:

          image=ImageIO.read(getClass().getResourceAsStream("/javaproject/Space.gif"));
    

    Edit for comment below: Since javaproject/ is not actually inside build/classes/, I guess you actually need:

          image=ImageIO.read(getClass().getResourceAsStream("/Space.gif"));
    

    (I know the context here is a bit different, but it should be clear that this system is modeled somewhat on a filesystem. If your build/classes/ directory doesn't contain a javaproject/ directory, then why would it ever occur to you to write build/classes/javaproject/?)

    0 讨论(0)
  • 2021-01-29 08:52

    The promblom is that its A system file so you got too do this:

    ClassLoader.getSystemResourceAsStream

    0 讨论(0)
提交回复
热议问题