Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

NullPointerException in resolverFactory.getServiceResourceResolver(param)

Avatar

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

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

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 1
View profile
azus_Khan
Level 1

25-01-2019

I am trying to access page properties using services in AEM 6.4

I have created  an interface,

public interface AccessPageProp {

public String getPageProp();

}

I have created a class that implements this interface,

@Component(service = AcccessPagePropImpl.class, immediate = true)

public class AcccessPagePropImpl implements AccessPageProp {

Logger logger = LoggerFactory.getLogger(AcccessPagePropImpl.class);

@Reference

private ResourceResolverFactory resolverFactory;

@Override

public String getPageProp() {

logger.info("Entering into getPageProp()...");

String title = "";

Map<String, Object> param = new HashMap<String, Object>();

param.put(ResourceResolverFactory.SUBSERVICE, "readService");

ResourceResolver resourceResolver = null;

try {

resourceResolver = resolverFactory.getServiceResourceResolver(param);

Resource pageResource = resourceResolver.getResource("/content/MyProject/en/TestPageName/jcr:content");

Page myPage = pageResource.adaptTo(Page.class);

title = myPage.getTitle();

return title;

} catch (Exception e) {

logger.info("Exception...."+e.toString());

e.printStackTrace();

}

return title;

}

}

I am getting "java.lang.NullPointerException" in line "resourceResolver = resolverFactory.getServiceResourceResolver(param);"

Replies

Avatar

Avatar
Give back 300
MVP
Gaurav-Behl
MVP

Likes

243 likes

Total Posts

1,145 posts

Correct Reply

281 solutions
Top badges earned
Give back 300
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Give back 300
MVP
Gaurav-Behl
MVP

Likes

243 likes

Total Posts

1,145 posts

Correct Reply

281 solutions
Top badges earned
Give back 300
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
Gaurav-Behl
MVP

25-01-2019

What versions of scr-annotations, maven-bundle-plugin and uber-jar do you use in 6.4?

Can you check in /system/console/bundles and /components that the service is generated/active?

Check if you have assigned appropriate permissions to the "readService" against the package name of bundle.

Could you also share the stack trace?

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

25-01-2019

Looks like you Sling Service Mapping may not have been configured properly. DId you use the Symbolic name of the OSGi bundle?

As @Gaurav Behl mentions too - ensure that your system user has the correct permissions.

I strongly recommend that you go through this HELPX Article. It will walk you through this use case on 6.4:

Adobe Experience Manager Help | Using the Sling Strongly-typed API to retrieve content from Adobe Ex...

It even uses the PageManager API.

Avatar

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

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

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 1
View profile
azus_Khan
Level 1

27-01-2019

I used the Symbolic name of my OSGi Bundle in user mapper service, I gave all the required permissions to my system user and I followed this article too but still I am getting Null Pointer Exception.

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

441 likes

Total Posts

1,022 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

441 likes

Total Posts

1,022 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

28-01-2019

Can you please paste the error log here. I doubt there should be something we can figure out from the error logs itself .

PS:- Do cross verify the imports for your @Reference .

Avatar

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

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

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 1
View profile
azus_Khan
Level 1

28-01-2019

I used below import statement for @Reference

import org.osgi.service.component.annotations.Reference;

I used logger to print exception in my catch block like,

catch (Exception e) {

logger.info("Exception...." + e.toString());

e.printStackTrace();

}

It prints the below message,

com.myproject.core.AcccessPagePropImpl Exception....java.lang.NullPointerException

Avatar

Avatar
Give back 300
MVP
Gaurav-Behl
MVP

Likes

243 likes

Total Posts

1,145 posts

Correct Reply

281 solutions
Top badges earned
Give back 300
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile

Avatar
Give back 300
MVP
Gaurav-Behl
MVP

Likes

243 likes

Total Posts

1,145 posts

Correct Reply

281 solutions
Top badges earned
Give back 300
Give Back 50
Give Back 5
Give Back 3
Give Back 25
View profile
Gaurav-Behl
MVP

28-01-2019

What versions of scr-annotations, maven-bundle-plugin and uber-jar do you use in 6.4?

Can you check in /system/console/bundles and /components that the service is generated/active?

Avatar

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

441 likes

Total Posts

1,022 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile

Avatar
Establish
MVP
Veena_Vikram
MVP

Likes

441 likes

Total Posts

1,022 posts

Correct Reply

115 solutions
Top badges earned
Establish
Coach
Contributor 2
Seeker
Ignite 5
View profile
Veena_Vikram
MVP

29-01-2019

Instead of logger.info("Exception...." + e.toString()); Could you replace + with ,  logger.info("Exception...." +, e);

This should print the entire stack trace for you.

Avatar

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

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

Avatar
Ignite 1
Level 1
azus_Khan
Level 1

Likes

2 likes

Total Posts

6 posts

Correct Reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 1
View profile
azus_Khan
Level 1

29-01-2019

My issue has been resolved when I used getSlingHelper() instead of creating a new object using new keyword in the Activate() ​method.

AccessPageProp accessPageProp = getSlingScriptHelper().getService(AccessPagePropImpl.class);

Avatar

Avatar
Affirm 1
Level 1
karl515-YhciiQ
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile

Avatar
Affirm 1
Level 1
karl515-YhciiQ
Level 1

Likes

0 likes

Total Posts

4 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile
karl515-YhciiQ
Level 1

14-05-2019

Hello,

I am getting the error your getting. may I know how did you resolve it?

but I have a different approach.

I am accessing "ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(param);:

in a PostConstruct init() class.