java.lang.NullPointerException------------------------
Query Builder createQuery code is not working in local When Im using query debugger for Testing of same predicated group objects it showing result but not with JAVA
Query query = queryBuilder.createQuery(PredicateGroup.create(searchMap), session);
This line not executing when im running the code.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @keshav_goud,
With Service Implementation (of QueryBuilder) bound, it shouldn't be null. Try restarting the QueryBuilderImpl OSGi component and/or its bundle - com.day.cq.cq-search.
Can you try to change the way we reference the QueryBuilder. If you are annotating it to an instance variable, try it with method or vice versa (With impl class bound per the screenshot you have shared, this shouldn't really make a difference. Just a try though)
Field/Instance variable annotation:
@Reference private QueryBuilder queryBuilder;
Method annotation:
private QueryBuilder queryBuilder; @Reference protected void bindQueryBuilder(QueryBuilder queryBuilder){ this.queryBuilder = queryBuilder; }
Can you share the complete servlet code if possible
Hi @keshav_goud
Can you please put your code here? Which line is throwing the error? I hope you are using system user to get the session.
Thanks!
Hi @Asutosh_Jena_ ,
Query query = queryBuilder.createQuery(PredicateGroup.create(searchMap), session);
this line giving null in try catch mode and session is from request.getResourceResolver(); it is a servlet im using
Hi @keshav_goud
Please use the below query.
Map<String, String> predicatesMap = new HashMap<>();
//Generate the query here. Adding a sample below for now.
predicatesMap.put(PREDICATE_FULLTEXT, Text.unescape(keyWord));
predicatesMap.put(PREDICATE_TYPE, NameConstants.NT_PAGE);
predicatesMap.put(PREDICATE_PATH, searchRootPath);
predicatesMap.put(PREDICATE_PROPERTY_OPERATION, PROPERTY_OPERATION_EXISTS);
predicatesMap.put(PREDICATE_PROPERTY_VALUE, String.valueOf(Boolean.FALSE));
predicatesMap.put(PREDICATE_LIMIT, "-1");
final PredicateGroup predicates = PredicateConverter.createPredicates(predicatesMap);
final Query query = queryBuilder.createQuery(predicates, resourceResolver.adaptTo(Session.class));
query.setExcerpt(Boolean.TRUE);
final SearchResult result = query.getResult();
Hope this helps!
Thanks!
hi @Asutosh_Jena_ ,
1.Query builder im calling in servlet by using @Reference
2.Same its again null showing here im using two properties comparing in a single resource both. can you give me that query in this way that appreciated. The query be like
Hi @keshav_goud,
Hope this helps.
Thanks,
Kiran Vedantam.
HI @Kiran_Vedantam ,
1. Query debugger results showing.
2. Currently im implementing in Servlet .Session Im getting from Resolver and it is from request not with the user mapping.
3. In JAVA code while im trying to print the class of query builder its showing NULL in logs
queryBuilder.createQuery(PredicateGroup.create(searchMap), session) throwing null.
Thanks,
Keshav
Hi @keshav_goud,
Can you cross check your servlet class in OSGi components console(http://localhost:4502/system/console/components) if it is active and if queryBuilder reference is satisfied/Bound to respective Service implementation.
If it is not, cross check
Hi @Vijayalakshmi_S ,
Its in Satisfied Status and active also ,any other solutions please suggest me.
Hi @keshav_goud,
With Service Implementation (of QueryBuilder) bound, it shouldn't be null. Try restarting the QueryBuilderImpl OSGi component and/or its bundle - com.day.cq.cq-search.
Can you try to change the way we reference the QueryBuilder. If you are annotating it to an instance variable, try it with method or vice versa (With impl class bound per the screenshot you have shared, this shouldn't really make a difference. Just a try though)
Field/Instance variable annotation:
@Reference private QueryBuilder queryBuilder;
Method annotation:
private QueryBuilder queryBuilder; @Reference protected void bindQueryBuilder(QueryBuilder queryBuilder){ this.queryBuilder = queryBuilder; }
Can you share the complete servlet code if possible
you are amazing!! I had been looking for ever and didn't realize I had the wrong import statement... thank you!
Remove the '/' at the end of the property name.
Views
Likes
Replies
Views
Like
Replies