<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting an exception in Model. in Adobe Experience Manager Discussions</title>
    <link>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372969#M26872</link>
    <description>&lt;P&gt;&lt;LI-USER uid="14630154"&gt;&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;org.apache.sling.models.factory.MissingElementException is thrown, when your Model is not able to inject the property. As per your exception trace, you have two properties artTitle and altText, which are not getting injected to the model.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;One possible reason could be, that the resource you are trying to adapt doesn't have these properties. To resolve the issue, you can follow either of the below:&lt;/P&gt;&lt;P&gt;1. Mark the private variable as "@Optional"&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;@Inject&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;@Optional&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;@Named&lt;/SPAN&gt;(&lt;SPAN&gt;"articleTitle"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;@SuppressWarnings&lt;/SPAN&gt;(&lt;SPAN&gt;"unchecked"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;private &lt;/SPAN&gt;&lt;SPAN&gt;String &lt;/SPAN&gt;&lt;SPAN&gt;artTitle&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;2. Change the class level Model annotation to include the default injection strategy as optional.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;@Model&lt;/SPAN&gt;(adaptables = &lt;SPAN&gt;Resource&lt;/SPAN&gt;.&lt;SPAN&gt;class&lt;/SPAN&gt;, defaultInjectionStrategy = &lt;SPAN&gt;DefaultInjectionStrategy&lt;/SPAN&gt;.&lt;SPAN&gt;OPTIONAL&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jul 2020 14:27:22 GMT</pubDate>
    <dc:creator>Fanindra_Surat</dc:creator>
    <dc:date>2020-07-31T14:27:22Z</dc:date>
    <item>
      <title>Getting an exception in Model.</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372890#M26866</link>
      <description>&lt;P&gt;Hello All - I am getting an exception in the Model class.Can someone advise on this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;@Model&lt;/SPAN&gt;(&lt;SPAN&gt;adaptables&lt;/SPAN&gt;=Resource.&lt;SPAN&gt;class&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;public class &lt;/SPAN&gt;ModelA{&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;@ValueMapValue&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;@Named&lt;/SPAN&gt;(&lt;SPAN&gt;"cq:lastReplicated"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;@Required&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;private &lt;/SPAN&gt;String &lt;SPAN&gt;lastReplicated&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;SPAN&gt;@Inject&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;@Named&lt;/SPAN&gt;(&lt;SPAN&gt;"articleTitle"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;@SuppressWarnings&lt;/SPAN&gt;(&lt;SPAN&gt;"unchecked"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;private &lt;/SPAN&gt;String &lt;SPAN&gt;artTitle&lt;/SPAN&gt;&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;07.30.2020 21:57:32.160 *WARN* [ anonymous-nosite-0:0:0:0:0:0:0:1-24170aab-c015-47e6-9c11-512d9d960aab ] &lt;STRONG&gt;org.apache.sling.models.impl.ModelAdapterFactory Could not adapt to model&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class com.xxx.yyy.aem.core.models.ModelA&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;org.apache.sling.models.impl.ModelAdapterFactory Could not adapt to model&lt;BR /&gt;org.apache.sling.models.factory.MissingElementsException: Could not inject all required fields into class com.xxx.yyy.aem.core.models.ModelA&lt;/P&gt;&lt;P&gt;Caused by: org.apache.sling.models.factory.ModelClassException: No injector returned a non-null value!&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Suppressed: org.apache.sling.models.factory.MissingElementException: Could not inject private java.lang.String com.xxx.yyy.aem.core.models.ModelA.artTitle&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:749)&lt;/STRONG&gt;&lt;BR /&gt;... 163 common frames omitted&lt;BR /&gt;Caused by: org.apache.sling.models.factory.ModelClassException: No injector returned a non-null value!&lt;BR /&gt;at org.apache.sling.models.impl.ModelAdapterFactory.injectElement(ModelAdapterFactory.java:635)&lt;BR /&gt;at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:744)&lt;BR /&gt;... 163 common frames omitted&lt;BR /&gt;&lt;STRONG&gt;Suppressed: org.apache.sling.models.factory.MissingElementException: Could not inject private java.lang.String com.xxx.yyy.aem.core.models.ModelA.altText&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;at org.apache.sling.models.impl.ModelAdapterFactory.createObject(ModelAdapterFactory.java:749)&lt;/STRONG&gt;&lt;BR /&gt;... 163 common frames omitted&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 02:08:39 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372890#M26866</guid>
      <dc:creator>v1101</dc:creator>
      <dc:date>2020-07-31T02:08:39Z</dc:date>
    </item>
    <item>
      <title>Looks to be the some fields are missing in the resource w...</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372896#M26867</link>
      <description>&lt;P&gt;Looks to be the some fields are missing in the resource while adapting into a model.&lt;/P&gt;&lt;P&gt;Try adding&amp;nbsp;&lt;LI-USER uid="7392697"&gt;&lt;/LI-USER&gt;&amp;nbsp;to those specific fields&lt;/P&gt;&lt;P&gt;e.g&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;@&lt;/SPAN&gt;&lt;SPAN class=""&gt;Inject&lt;/SPAN&gt;&lt;STRONG&gt;&amp;nbsp;&lt;LI-USER uid="7392697"&gt;&lt;/LI-USER&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;private String otherName;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;If the majority of the fields are optional then specify at the class level&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;e.g&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;@&lt;SPAN class=""&gt;Model&lt;/SPAN&gt;(&lt;SPAN class=""&gt;adaptables&lt;/SPAN&gt;=&lt;SPAN class=""&gt;Resource&lt;/SPAN&gt;.&lt;SPAN class=""&gt;class&lt;/SPAN&gt;, &lt;STRONG&gt;defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL&lt;/STRONG&gt;) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;public class MyModel {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Albin I&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;A href="http://www.albinsblog.com" target="_blank" rel="noopener"&gt;www.albinsblog.com&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 03:56:44 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372896#M26867</guid>
      <dc:creator>Albin_Issac</dc:creator>
      <dc:date>2020-07-31T03:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: Getting an exception in Model.</title>
      <link>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372969#M26872</link>
      <description>&lt;P&gt;&lt;LI-USER uid="14630154"&gt;&lt;/LI-USER&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;org.apache.sling.models.factory.MissingElementException is thrown, when your Model is not able to inject the property. As per your exception trace, you have two properties artTitle and altText, which are not getting injected to the model.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;One possible reason could be, that the resource you are trying to adapt doesn't have these properties. To resolve the issue, you can follow either of the below:&lt;/P&gt;&lt;P&gt;1. Mark the private variable as "@Optional"&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;@Inject&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;@Optional&lt;/STRONG&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;@Named&lt;/SPAN&gt;(&lt;SPAN&gt;"articleTitle"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;@SuppressWarnings&lt;/SPAN&gt;(&lt;SPAN&gt;"unchecked"&lt;/SPAN&gt;)&lt;BR /&gt;&lt;SPAN&gt;private &lt;/SPAN&gt;&lt;SPAN&gt;String &lt;/SPAN&gt;&lt;SPAN&gt;artTitle&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;P&gt;2. Change the class level Model annotation to include the default injection strategy as optional.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;@Model&lt;/SPAN&gt;(adaptables = &lt;SPAN&gt;Resource&lt;/SPAN&gt;.&lt;SPAN&gt;class&lt;/SPAN&gt;, defaultInjectionStrategy = &lt;SPAN&gt;DefaultInjectionStrategy&lt;/SPAN&gt;.&lt;SPAN&gt;OPTIONAL&lt;/SPAN&gt;)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 14:27:22 GMT</pubDate>
      <guid>https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/getting-an-exception-in-model/m-p/372969#M26872</guid>
      <dc:creator>Fanindra_Surat</dc:creator>
      <dc:date>2020-07-31T14:27:22Z</dc:date>
    </item>
  </channel>
</rss>

