Results 1 to 6 of 6
  1. #1
    LovJava is offline Member
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Default Width (-1) and height (-1) cannot be <= 0

    Hi Everybody,

    In my project i am printing the jasper report and report contains the image. If there is an existing image then it will display, if not it will give the below error. any body pls help me. what might be cause?


    java.lang.IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0
    at java.awt.image.DirectColorModel.createCompatibleWr itableRaster(Unknown Source)
    at java.awt.image.BufferedImage.<init>(Unknown Source)
    at net.sf.jasperreports.engine.util.JRAbstractImageEn coder.encode(JRAbstractImageEncoder.java:59)
    at net.sf.jasperreports.engine.util.JRImageLoader.loa dImageDataFromAWTImage(JRImageLoader.java:166)
    at net.sf.jasperreports.engine.JRImageRenderer.getIns tance(JRImageRenderer.java:233)
    at net.sf.jasperreports.engine.JRImageRenderer.getIns tance(JRImageRenderer.java:216)
    at net.sf.jasperreports.engine.fill.JRFillImage.evalu ateImage(JRFillImage.java:457)
    at net.sf.jasperreports.engine.fill.JRFillImage.evalu ate(JRFillImage.java:426)
    at net.sf.jasperreports.engine.fill.JRFillElementCont ainer.evaluate(JRFillElementContainer.java:274)
    at net.sf.jasperreports.engine.fill.JRFillBand.evalua te(JRFillBand.java:400)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller. fillColumnBand(JRVerticalFiller.java:1273)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller. fillDetail(JRVerticalFiller.java:614)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller. fillReportStart(JRVerticalFiller.java:209)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller. fillReport(JRVerticalFiller.java:109)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill (JRBaseFiller.java:751)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill (JRBaseFiller.java:679)
    at net.sf.jasperreports.engine.fill.JRFiller.fillRepo rt(JRFiller.java:89)
    at net.sf.jasperreports.engine.JasperFillManager.fill Report(JasperFillManager.java:601)
    at net.sf.jasperreports.engine.JasperFillManager.fill Report(JasperFillManager.java:517)
    at net.sf.jasperreports.engine.JasperRunManager.runRe portToPdf(JasperRunManager.java:385)
    at org.apache.jsp.print.printDriverDetails_jsp._jspSe rvice(printDriverDetails_jsp.java:140)
    at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:263)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:584)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source):mad:

  2. #2
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    952
    Rep Power
    5

    Default

    Seems pretty clear to me. You are trying to call the method createCompatibleWritableRaster() on a DirectColorModel object with width and height parameters both set to -1, and that is not allowed. The message will have told you exactly which line of your source code is doing that, so fix it.

    -Gary-

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    you just catch the exception java.lang.IllegalArgumentException: and forget about it :)
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Webuser View Post
    you just catch the exception java.lang.IllegalArgumentException: and forget about it :)
    Yes, that'll be another source of mysterious bugs because some moron programmer muffled away an exception so it stays unnoticed. Don't ever do that.

    kind regards,

    Jos

  5. #5
    LovJava is offline Member
    Join Date
    Jan 2010
    Posts
    24
    Rep Power
    0

    Default

    hi gcalvin,

    You are trying to call the method createCompatibleWritableRaster() on a DirectColorModel object
    I havent called it any where.
    The message will have told you exactly which line of your source code is doing that
    ya this i right . Just check the below code. where i have commented line wher the error is occuring.
    Java Code:
    <%
    	try
        {
               String idDriver=request.getParameter("idDriver");
    
               Connection con=Session.getConnection();
               VODriver vo=new VODriver();
               vo.setIdDriver(new Integer(idDriver));
               vo.setProfit(new Integer(1));
               vo=DAODriver.DAO_SINGLETON.selectFirstByVO(con,vo);
    
    
               String query = "select * from drivers where id_driver='"+idDriver+"'";
               Statement stmt=con.createStatement();
               ResultSet rs = stmt.executeQuery(query);
               JRResultSetDataSource jrRS = new JRResultSetDataSource(rs);
    
    
               File reportFile = new File(application.getRealPath("/print/jasper/driverDetails.jasper"));
    
               //Preparing parameters
               String imge="/images/logo.jpg";
               
               java.awt.Image logo = java.awt.Toolkit.getDefaultToolkit().createImage(application.getRealPath(imge));
               logo.flush();
               java.awt.MediaTracker traker = new java.awt.MediaTracker(new java.awt.Panel());
             
             	
               traker.addImage(logo, 0);
               try
               {
                 traker.waitForID(0);
               }
               catch (Exception e)
               {
                 e.printStackTrace();
               }
    			
               //Preparing parameters
               Map<String, Object> parameters = new HashMap<String, Object>();
               parameters.put("ReportTitle", "Address Report");
               parameters.put("BaseDir", reportFile.getParentFile());
               parameters.put("logo", logo);
               
            
               if (vo.getPhotograph() != null) {
    	           java.awt.Image foto = java.awt.Toolkit.getDefaultToolkit().createImage(application.getRealPath("/file/"+vo.getPhotograph()));
    	           traker = new java.awt.MediaTracker(new java.awt.Panel());
    	           traker.addImage(foto, 0,129,140);
    	         
    	           try
    	           {
    	             traker.waitForID(0);
    	           }
    	           catch (Exception e)
    	           {
    	             e.printStackTrace();
    	           }
    	           parameters.put("foto", foto);
               }
               
    /*   Here i am getting the error in tomcat work location       */
               byte[] bytes = JasperRunManager.runReportToPdf(
                              reportFile.getPath(),
                              parameters,
                              jrRS
                              );
               
            	
    			 
           	   response.setContentType("application/pdf");
               response.setContentLength(bytes.length);
               ServletOutputStream ouputStream = response.getOutputStream();
    
               ouputStream.write(bytes, 0, bytes.length);
               ouputStream.flush();
               ouputStream.close();
               rs.close();
               stmt.close();
        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
        
    %>
    Last edited by LovJava; 04-20-2010 at 09:33 AM.

  6. #6
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    That's the beauty of frameworks. You get 50-line-long stack trace and not a single line is yours.

    Here's what I'm thinking:

    1. make absolutely sure the image does exist on the path where you're looking it up from. It's always embarrassing when this ends up being the issue.

    2. it could be that your image has not been fully loaded yet when you're calling runReportToPdf(). yes, you're using MediaTracker to make sure the image is done loading, but perhaps MediaTracker cleverly discovers that the java.awt.Panel you gave it never shows up on the screen, and thus no tracking needs to happen. Who knows.

    to debug the problem, try printing out image.getWidth() and image.getHeight() before runReportToPdf(). If ImageTracker is messing with you, you'll see "-1"

    to fix the problem, try using ImageIO.read (file), which fully loads the image before giving it to you. Also, you may want to try new MediaTracker(null) and seeing whether that makes any difference

Similar Threads

  1. height of the image.
    By programmer_007 in forum Java 2D
    Replies: 13
    Last Post: 02-18-2010, 01:17 PM
  2. I want set HEIGHT, WIDTH for Button
    By manhtungtnk28@gmail.com in forum AWT / Swing
    Replies: 3
    Last Post: 11-16-2009, 08:26 AM
  3. Using setBounds (x.y,width,height) constructor
    By hitmen in forum AWT / Swing
    Replies: 3
    Last Post: 03-06-2009, 01:12 PM
  4. Get Image Height and Width
    By neeraj.singh in forum AWT / Swing
    Replies: 10
    Last Post: 02-18-2009, 02:09 PM
  5. dynamising the height of a JPopupMenu
    By iimasd in forum AWT / Swing
    Replies: 6
    Last Post: 11-21-2007, 11:01 AM

Posting Permissions

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