title: JRException Resource not found at when there is a subreport in Jasper Report
body: <p>I made a jasper report that includes a subreport using JasperSoft Studio. When i preview it in the studio, it works fine. But when i add it into my java fx project, i have to send the subreport as a parameter to the main report right?</p>
  
  <p>When i do that i keep on getting an error saying that the subreport resource not found.
  I dont think there is any spelling errors because i hv tried this with almost all the reports that includes subreports.. still keep on getting that error..</p>
  
  <p>These are the things i tried
  1. compiled the report again using the jaspersoft studio and includeded them again in the project..
  2. included the jrxml file into the project and compiled it with the Compile Manager..
  3. i read some tutorials and questions saying that to put the expression to the subreport element in the main report as </p>
  
  <blockquote>
    <p>$P{SUBREPORT_DIR} + "subreport_2.jasper"</p>
  </blockquote>
  
  <p>but i still keep on getting the same error and i dont know what i am doing wrong
  Below is my code</p>
  
  <p>method in application used to view the report</p>
  
  <pre><code>@FXML
      public void btnMarkingSchemeClicked(ActionEvent actionEvent) {
          try {
  
  //            JasperReport compiledReport = (JasperReport) JRLoader.loadObject(ViewAssignmentsController.class.getResourceAsStream("/edu/ijse/gdse41/ams/reports/MarkingScheme.jasper"));
              JasperReport compiledReport = JasperCompileManager.compileReport(ViewAssignmentsController.class.getResourceAsStream("/edu/ijse/gdse41/ams/reports/MarkingScheme.jrxml"));
              HashMap&lt;String, Object&gt; parameters = new HashMap&lt;&gt;();
              parameters.put("assignID", aid);
              parameters.put("course", cmbCourse.getSelectionModel().getSelectedItem().toString());
              parameters.put("subject", cmbSub.getSelectionModel().getSelectedItem().toString());
              parameters.put("semester", cmbSem.getSelectionModel().getSelectedItem().toString());
              parameters.put("assign", ctrlAssign.search(aid).getAssignName());
  //            JasperReport subReport = (JasperReport) JRLoader.loadObject(ViewAssignmentsController.class.getResourceAsStream("/edu/ijse/gdse41/ams/reports/Answers.jasper"));
              JasperReport subReport = JasperCompileManager.compileReport(ViewAssignmentsController.class.getResourceAsStream("/edu/ijse/gdse41/ams/reports/Answers.jrxml"));
              parameters.put("subReport", subReport);
              JasperPrint fillReport = JasperFillManager.fillReport(compiledReport, parameters, ConnectionFactory.getInstance().getConnection());
              JasperViewer.viewReport(fillReport, false);
  
          } catch (JRException | SQLException | ClassNotFoundException ex) {
              Logger.getLogger(ViewAssignmentsController.class.getName()).log(Level.SEVERE, null, ex);
          }
  
      }
  </code></pre>
  
  <p>my main report source -- MarkingScheme.jrxml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --&gt;
  &lt;!-- 2017-06-02T12:52:20 --&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="MarkingScheme" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c71b946b-2ba2-4208-97f8-f32e8bcf3fb4"&gt;
      &lt;property name="com.jaspersoft.studio.data.sql.tables" value=""/&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="amsAdapter"/&gt;
      &lt;parameter name="course" class="java.lang.String"/&gt;
      &lt;parameter name="subject" class="java.lang.String"/&gt;
      &lt;parameter name="semester" class="java.lang.String"/&gt;
      &lt;parameter name="assign" class="java.lang.String"/&gt;
      &lt;parameter name="assignID" class="java.lang.String"&gt;
          &lt;defaultValueExpression&gt;&lt;![CDATA[$P{assignID}]]&gt;&lt;/defaultValueExpression&gt;
      &lt;/parameter&gt;
      &lt;parameter name="subReport" class="net.sf.jasperreports.engine.JasperReport"&gt;
          &lt;parameterDescription&gt;&lt;![CDATA[]]&gt;&lt;/parameterDescription&gt;
          &lt;defaultValueExpression&gt;&lt;![CDATA[$P{subReport}]]&gt;&lt;/defaultValueExpression&gt;
      &lt;/parameter&gt;
      &lt;queryString language="SQL"&gt;
          &lt;![CDATA[SELECT ams.question.qid,
      ams.question.question,
      ams.assign_ques.aid
  FROM ams.assign_ques
      INNER JOIN ams.question ON 
       ams.assign_ques.qid = ams.question.qid and ams.assign_ques.aid=$P{assignID}]]&gt;
      &lt;/queryString&gt;
      &lt;field name="qid" class="java.lang.String"/&gt;
      &lt;field name="question" class="java.lang.String"/&gt;
      &lt;field name="aid" class="java.lang.String"/&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;title&gt;
          &lt;band height="79" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement mode="Opaque" x="0" y="0" width="555" height="79" forecolor="#FFFFFF" backcolor="#113891" uuid="52ed193a-ed11-46ba-a09f-1864b843df96"/&gt;
                  &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                      &lt;font size="29" isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[   Marking Scheme]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/title&gt;
      &lt;pageHeader&gt;
          &lt;band height="80" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="0" y="0" width="80" height="40" uuid="55b35bb0-5ea8-4417-88be-0083cfee5037"/&gt;
                  &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                      &lt;font size="14"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Course]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="0" y="40" width="80" height="40" uuid="1dc04c2d-9cde-4905-9650-03cc96d406e3"/&gt;
                  &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                      &lt;font size="14"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Semester]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="260" y="0" width="100" height="40" uuid="4de2dbe2-bb88-4dbf-88d7-16b36bba8fb4"/&gt;
                  &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                      &lt;font size="14"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Subject]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="260" y="40" width="100" height="40" uuid="bb91c5d3-4cde-45eb-8083-012fe6183396"/&gt;
                  &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                      &lt;font size="14"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Assignment]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
              &lt;textField&gt;
                  &lt;reportElement x="90" y="0" width="160" height="40" forecolor="#123278" uuid="8016c655-1bea-480a-9179-3da4e1e930ad"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="13"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{course}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="370" y="0" width="170" height="40" forecolor="#123278" uuid="23e58b4b-0bf1-41ae-89f0-48808a0abdd9"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="13"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{subject}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="90" y="40" width="160" height="40" forecolor="#123278" uuid="650c412a-0c42-4dea-a96f-35d03c11c926"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="13"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{semester}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="370" y="40" width="170" height="40" forecolor="#123278" uuid="c8cbea5b-afb3-4c85-a96a-156d1c82fb50"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="13"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$P{assign}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/pageHeader&gt;
      &lt;columnHeader&gt;
          &lt;band height="30" splitType="Stretch"&gt;
              &lt;staticText&gt;
                  &lt;reportElement x="0" y="0" width="100" height="30" uuid="f7b84a13-8e80-4c9c-8888-3b081f9d0f55"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="16" isBold="true"/&gt;
                  &lt;/textElement&gt;
                  &lt;text&gt;&lt;![CDATA[Questions]]&gt;&lt;/text&gt;
              &lt;/staticText&gt;
          &lt;/band&gt;
      &lt;/columnHeader&gt;
      &lt;detail&gt;
          &lt;band height="41" splitType="Stretch"&gt;
              &lt;textField&gt;
                  &lt;reportElement x="0" y="0" width="80" height="20" uuid="9f05a7d2-ac5f-4412-b26b-ab37033cc0fe"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="12"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{qid}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="100" y="0" width="440" height="20" uuid="a299bfe0-a0d1-4aae-8f75-5b58d24b1760"/&gt;
                  &lt;textElement verticalAlignment="Middle"&gt;
                      &lt;font size="12"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{question}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;subreport&gt;
                  &lt;reportElement x="100" y="20" width="440" height="20" uuid="72f8c7c2-82ca-48d3-bb89-d5bb4846e1bc"/&gt;
                  &lt;subreportParameter name="qid"&gt;
                      &lt;subreportParameterExpression&gt;&lt;![CDATA[$F{qid}]]&gt;&lt;/subreportParameterExpression&gt;
                  &lt;/subreportParameter&gt;
                  &lt;connectionExpression&gt;&lt;![CDATA[$P{REPORT_CONNECTION}]]&gt;&lt;/connectionExpression&gt;
                  &lt;subreportExpression&gt;&lt;![CDATA["Answers.jasper"]]&gt;&lt;/subreportExpression&gt;
              &lt;/subreport&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>my sub report source -- Answers.jrxml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  --&gt;
  &lt;!-- 2017-06-02T12:53:52 --&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Answers" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="142adbc1-da50-458b-b076-ba8aa716124f"&gt;
      &lt;property name="com.jaspersoft.studio.data.defaultdataadapter" value="amsAdapter"/&gt;
      &lt;property name="com.jaspersoft.studio.data.sql.tables" value="YW1zLmFuc3dlciAsMTUsMTUsOGE1MjQ1NzQtOGY1ZS00ZWY4LWFiMDAtOWVjYmVmNmU0MTFjOw=="/&gt;
      &lt;parameter name="qid" class="java.lang.String"&gt;
          &lt;defaultValueExpression&gt;&lt;![CDATA[$P{qid}]]&gt;&lt;/defaultValueExpression&gt;
      &lt;/parameter&gt;
      &lt;queryString&gt;
          &lt;![CDATA[SELECT ams.answer.answer_id,
      ams.answer.answer,
      ams.answer.correctness,
      ams.answer.qid
  FROM ams.answer where ams.answer.qid=$P{qid} and ams.answer.correctness=1]]&gt;
      &lt;/queryString&gt;
      &lt;field name="answer_id" class="java.lang.String"/&gt;
      &lt;field name="answer" class="java.lang.String"/&gt;
      &lt;field name="correctness" class="java.lang.Boolean"/&gt;
      &lt;field name="qid" class="java.lang.String"/&gt;
      &lt;background&gt;
          &lt;band splitType="Stretch"/&gt;
      &lt;/background&gt;
      &lt;detail&gt;
          &lt;band height="20" splitType="Stretch"&gt;
              &lt;textField&gt;
                  &lt;reportElement x="0" y="0" width="80" height="20" uuid="517ba9e8-6637-4808-8517-1485d4125971"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="12"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{answer_id}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
              &lt;textField&gt;
                  &lt;reportElement x="90" y="0" width="460" height="20" uuid="4384510c-5dea-47a0-b24b-d4b3bd4088fc"/&gt;
                  &lt;textElement&gt;
                      &lt;font size="12"/&gt;
                  &lt;/textElement&gt;
                  &lt;textFieldExpression&gt;&lt;![CDATA[$F{answer}]]&gt;&lt;/textFieldExpression&gt;
              &lt;/textField&gt;
          &lt;/band&gt;
      &lt;/detail&gt;
  &lt;/jasperReport&gt;
  </code></pre>
  
  <p>the error im getting</p>
  
  <blockquote>
    <p>net.sf.jasperreports.engine.JRException: Resource not found at:
    Answers.jasper.   at
    net.sf.jasperreports.repo.RepositoryUtil.getResourceFromLocation(RepositoryUtil.java:153)
      at
    net.sf.jasperreports.repo.RepositoryUtil.getReport(RepositoryUtil.java:112)
      at
    net.sf.jasperreports.engine.fill.JRFillSubreport.loadReport(JRFillSubreport.java:398)
      at
    net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateReport(JRFillSubreport.java:365)
      at
    net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:427)
      at
    net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:341)
      at
    net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:381)
      at
    net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:500)
      at
    net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2022)
      at
    net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:748)
      at
    net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
      at
    net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:115)
      at
    net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:582)
      at
    net.sf.jasperreports.engine.fill.BaseReportFiller.fill(BaseReportFiller.java:396)
      at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:90)
      at
    net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:456)
      at
    net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:863)
      at
    edu.ijse.gdse41.ams.view.controller.ViewAssignmentsController.btnMarkingSchemeClicked(ViewAssignmentsController.java:174)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)     at
    sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)    at
    sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)   at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)     at
    sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)   at
    javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)     at
    javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
      at
    com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
      at
    com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at
    com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at
    com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at
    com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at
    com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at
    com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at
    com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at
    com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at
    com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)  at
    javafx.event.Event.fireEvent(Event.java:198)  at
    javafx.scene.Node.fireEvent(Node.java:8413)   at
    javafx.scene.control.Button.fire(Button.java:185)     at
    com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
      at
    com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
      at
    com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
      at
    com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
      at
    com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
      at
    com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
      at
    com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
      at
    com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
      at
    com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
      at
    com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at
    com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at
    com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at
    com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
      at
    com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
      at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
      at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)  at
    javafx.event.Event.fireEvent(Event.java:198)  at
    javafx.scene.Scene$MouseHandler.process(Scene.java:3757)  at
    javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)  at
    javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)    at
    javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)  at
    com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
      at
    com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
      at java.security.AccessController.doPrivileged(Native Method)   at
    com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417)
      at
    com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
      at
    com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
      at com.sun.glass.ui.View.handleMouseEvent(View.java:555)    at
    com.sun.glass.ui.View.notifyMouse(View.java:937)  at
    com.sun.glass.ui.win.WinApplication._runLoop(Native Method)   at
    com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
      at java.lang.Thread.run(Thread.java:745)</p>
  </blockquote>