0

I have a problem reading an image, the image is located in the src/iamges/logo.jpg............

JFreeChart jfreechart = ChartFactory.createGanttChart("Actividades", "Actividad", "Fecha", cratedataSet(getListaactividades()));

BufferedImage img = ImageIO.read(new File("/src/demo/logiepn.jpg"));
jfreechart.setBackgroundImage(img);

File chartFile = new File("dynamichart");  

   ChartUtilities.saveChartAsPNG(chartFile, jfreechart, 720, 400);  
   chart = new DefaultStreamedContent(new FileInputStream(chartFile), "image/png");  

and the error is:

Caused by: javax.imageio.IIOException: Can't read input file!
    at javax.imageio.ImageIO.read(ImageIO.java:1275) [rt.jar:1.6.0_21]
    at ec.edu.epn.proyectos.backingbean.proyectosAprobados.InformeProycierreproy(proyectosAprobados.java:227) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_21]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_21]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_21]
    at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_21]
    at org.apache.el.parser.AstValue.invoke(AstValue.java:264) [jbossweb-7.0.17.Final.jar:]
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.17.Final.jar:]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.11-jbossorg-3.jar:]
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) [jboss-jsf-api_2.1_spec-2.0.4.Final.jar:2.0.4.Final]
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • Just to check... You are trying read an image located in `src/iamges/logo.jpg`, using the path `"/src/demo/logiepn.jpg"`? And you are surprised it doesn't work..? – Harald K Jan 15 '14 at 15:32
  • The "/" at the beginning of "/src/demo/logiepn.jpg" does refer to the filesystem root and not the root of your application directory. – Nick Russler Jan 15 '14 at 15:33

1 Answers1

0

Your path is wrong, take a look at the answers of this question:

Load Java Image inside package from a class in a different package

Community
  • 1
  • 1
Nick Russler
  • 4,608
  • 6
  • 51
  • 88