NullPointerException Using QueryBuilder is JAVA USe API extending WCMUSePojo | Community
Skip to main content
Raghava_Joijode
Level 2
April 13, 2017
Solved

NullPointerException Using QueryBuilder is JAVA USe API extending WCMUSePojo

  • April 13, 2017
  • 2 replies
  • 1964 views

Hi All,

 

I am getting NullPointerException at -->  Query query = builder.createQuery(PredicateGroup.create(map), session);

I have used -->

    @Reference
    private QueryBuilder builder ;
before (Outside)  activate method.

Code Snip:::

Map<String, Object> map = new HashMap<String, Object>();
        map.put("type", "cq:Page");
        map.put("path", roothPath);
        map.put("1_property", "=@jcr:content/someprop");
        map.put("1_property.value", "somevalue");
        map.put("1_property.operation", "like");
        map.put("orderby", "@jcr:content/jcr:lastmodified");
        map.put("orderby.sort", "desc");
        map.put("p.limit", "-1");
        Query query = builder.createQuery(PredicateGroup.create(map), session);
        
        SearchResult result = query.getResult();

 

Can anyone suggest where am i missing this.

 

Thanks,

Raghava.

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 Raghava_Joijode

Got My Mistake,

@Override
    public void activate() throws Exception {

        resolver = getResourceResolver();
        session = resolver.adaptTo(Session.class);
        builder = getSlingScriptHelper().getService(QueryBuilder.class); instead of reference

    }

2 replies

Raghava_Joijode
Raghava_JoijodeAuthorAccepted solution
Level 2
April 13, 2017

Got My Mistake,

@Override
    public void activate() throws Exception {

        resolver = getResourceResolver();
        session = resolver.adaptTo(Session.class);
        builder = getSlingScriptHelper().getService(QueryBuilder.class); instead of reference

    }

Feike_Visser1
Adobe Employee
Adobe Employee
April 13, 2017

Other possibility is to use Sling-Models, then you can use the @Inject annotation.