NullPointerException in resolverFactory.getServiceResourceResolver(param) | Community
Skip to main content
Level 2
Jan 25, 2019 11:23 AM UTC

NullPointerException in resolverFactory.getServiceResourceResolver(param)

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

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

11 replies

azus_KhanAuthor
Level 2
Jan 29, 2019 9:49 AM UTC

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);

Translate
karl515-YhciiQ
New Participant
May 15, 2019 3:17 AM UTC

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.

Translate
VeenaVikraman
New Participant
May 22, 2019 10:08 AM UTC

karl515-qd9WHG​

    Are your service user available for the bundle ? Do you get any error in the logs ?

Thanks

Veena

Translate
Gaurav-Behl
Level 10
Jan 25, 2019 12:18 PM UTC

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?

Translate
smacdonald2008
Level 10
Jan 25, 2019 3:59 PM UTC

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 Experience Manager 6.4

It even uses the PageManager API.

Translate
azus_KhanAuthor
Level 2
Jan 28, 2019 7:41 AM UTC

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.

Translate