Getting error log "AEM failed to activate Use class"

Avatar

Avatar
Validate 1
Level 1
ShagunMalik
Level 1

Like

1 like

Total Posts

55 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
Ignite 1
Give Back
View profile

Avatar
Validate 1
Level 1
ShagunMalik
Level 1

Like

1 like

Total Posts

55 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
Ignite 1
Give Back
View profile
ShagunMalik
Level 1

29-06-2021

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_M 

@Dipti_Chauhan Please suggest.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

126 likes

Total Posts

144 posts

Correct reply

41 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

126 likes

Total Posts

144 posts

Correct reply

41 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile
Dipti_Chauhan
Level 6

29-06-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");

Answers (4)

Answers (4)

Avatar

Avatar
Boost 5
Level 2
GnanendraPonnala
Level 2

Likes

5 likes

Total Posts

14 posts

Correct reply

2 solutions
Top badges earned
Boost 5
Establish
Affirm 1
Boost 3
Boost 1
View profile

Avatar
Boost 5
Level 2
GnanendraPonnala
Level 2

Likes

5 likes

Total Posts

14 posts

Correct reply

2 solutions
Top badges earned
Boost 5
Establish
Affirm 1
Boost 3
Boost 1
View profile
GnanendraPonnala
Level 2

29-06-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.

}

Avatar

Avatar
Affirm 25
Level 5
Bimmi_Soi
Level 5

Likes

79 likes

Total Posts

83 posts

Correct reply

28 solutions
Top badges earned
Affirm 25
Contributor
Applaud 5
Boost 50
Ignite 1
View profile

Avatar
Affirm 25
Level 5
Bimmi_Soi
Level 5

Likes

79 likes

Total Posts

83 posts

Correct reply

28 solutions
Top badges earned
Affirm 25
Contributor
Applaud 5
Boost 50
Ignite 1
View profile
Bimmi_Soi
Level 5

29-06-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

Avatar

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

126 likes

Total Posts

144 posts

Correct reply

41 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

126 likes

Total Posts

144 posts

Correct reply

41 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile
Dipti_Chauhan
Level 6

29-06-2021

Hi @Sh 

 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

 

Avatar

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct reply

45 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct reply

45 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Ritesh_M
Level 7

29-06-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?