Expand my Community achievements bar.

SOLVED

NullPointerException Using QueryBuilder is JAVA USe API extending WCMUSePojo

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Level 3

Got My Mistake,

@Override
    public void activate() throws Exception {

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

    }

View solution in original post

2 Replies

Avatar

Correct answer by
Level 3

Got My Mistake,

@Override
    public void activate() throws Exception {

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

    }

Avatar

Employee

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