Getting error log "AEM failed to activate Use class" | Community
Skip to main content
Level 3
Jun 29, 2021 9:59 AM UTC
Solved

Getting error log "AEM failed to activate Use class"

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.
Dipti_Chauhan
Dipti_ChauhanAccepted solution
New Participant
Jun 29, 2021 10:37 AM UTC

Hi @shagunmalik 

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

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

18 replies

Level 3
Jun 29, 2021 11:55 AM UTC

Thank you everyone.

@gnanendraponnala @bimmiso @ritesh_mittal @dipti_chauhan 

Translate
GnanendraPonnala
Level 2
Jun 29, 2021 11:28 AM UTC

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.

}

Translate
Level 3
Jun 29, 2021 11:34 AM UTC

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.

Translate
Employee
Jun 29, 2021 11:21 AM UTC

@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

Translate
Dipti_Chauhan
Dipti_ChauhanAccepted solution
New Participant
Jun 29, 2021 10:37 AM UTC

Hi @shagunmalik 

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

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

Translate
Level 3
Jun 29, 2021 10:43 AM UTC
@dipti_chauhan, thank you for that but the issue is still the same. I'm getting error as above and it is throwing NullPoineterException: null.
Translate
Dipti_Chauhan
New Participant
Jun 29, 2021 10:14 AM UTC

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

 

Translate
Ritesh_Mittal
New Participant
Jun 29, 2021 10:09 AM UTC

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?

Translate
Level 3
Jun 29, 2021 10:18 AM UTC
Yes @ritesh_mittal, I'm getting NullPoineterException: null
Translate