Getting error log "AEM failed to activate Use class" | Community
Skip to main content
Level 3
June 29, 2021
Solved

Getting error log "AEM failed to activate Use class"

  • June 29, 2021
  • 6 replies
  • 4819 views

Hey Community

I have wriiten this basic code to get cq:tags property of current page

public Void activate throws exception{

rootpage=getCurrentPage;

Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content/");

         ValueMap pageProperties = res .getValueMap();

         tag= (String) pageProperties.get("cq:tags", "Default value");

logger.info(tag);

}

 

When I'm using creating object using HTL statement in HTMl file it is not displaying anything on page and error log says "AEM failed to activate Use class"

How to resolve it?

@ritesh_mittal 

@dipti_chauhan Please suggest.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Dipti_Chauhan

Hi @shagunmalik 

BTW there is no need to add slash after jcr:content. It should be 

Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");

6 replies

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 29, 2021

Hi @shagunmalik ,

 

You must be getting some exception like NullPoineterException or something in the logs which is happening inside Active method of your class. Could you provide the error logs?

Level 3
June 29, 2021
Yes @ritesh_mittal, I'm getting NullPoineterException: null
Dipti_Chauhan
Community Advisor
Community Advisor
June 29, 2021

Hi @329280 

 May be there is some exception in activate method. Please debug your code using debugger and find out where you getting exception.

 

And normally you should not write any logic inside activate method. Create different getter to get properties because if there is any issue in you code written within activate method your class activation will get failed

 

Thanks

Dipti

 

Dipti_Chauhan
Community Advisor
Dipti_ChauhanCommunity AdvisorAccepted solution
Community Advisor
June 29, 2021

Hi @shagunmalik 

BTW there is no need to add slash after jcr:content. It should be 

Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");

Dipti_Chauhan
Community Advisor
Community Advisor
June 29, 2021
you need to debug this. At what point you getting NLP. could be your resource null or resourceresolver object is null.
Adobe Employee
June 29, 2021

@shagunmalik ,

 

Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content/");

remove the slash from the end

Resource res = getResourceResolver.getResource(rootpage.getPath()+"/jcr:content");

 

if still the issue persists add loggers or run your class in debug mode to get the exact line where there is exception

 

Hope this helps

GnanendraPonnala
Level 2
June 29, 2021

Hi @shagunmalik ,

 

Could you please verify below line

tag= (String) pageProperties.get("cq:tags", "Default value");

 

By Default  cq:tags are String Array not a String Field 

String[] tagArrays =  pageProperties.get("cq:tags", String[].class);

if(Objects.nonNull(tagArrays ) && tagArrays .length>0) {

     tag = tagArrays[0]; -- will give first value in array.

}

Level 3
June 29, 2021

Hey, @gnanendraponnala  I get your point but Even if I'm trying to access any other property of page which is of type String such as cq:template then still it is not working.

Level 3
June 29, 2021