Expand my Community achievements bar.

SOLVED

Issue in SimpleSearch.class

Avatar

Level 4

Hi there,

I tried to use the simpleSearchto achieve the  search functionality

When I try to use the below one.

slingRequest.getResource().adaptTo(SimpleSearch.class);

I got nullpointer exception.

Kindly guide me to resolve the issue. 

Thanks

Nanda

1 Accepted Solution

Avatar

Correct answer by
Level 10

Make sure you have included the 'cq-search' dependency in your project

View solution in original post

6 Replies

Avatar

Correct answer by
Level 10

Make sure you have included the 'cq-search' dependency in your project

Avatar

Level 10

Why not use QueryBuilder API instead of SimpleSearch? 

Avatar

Level 10
<dependency><groupId>com.day.cq</groupId><artifactId>cq-search</artifactId><version>5.5.4</version></dependency>

Avatar

Level 4

Thanks for your reply.

Dependency is already exist in my POM.xml.

I can import the SimpleSearch class in my code. 

When I try to print  'slingRequest.getResource()' in the console. I can see the object reference.

But when I try with adaptTo(SimpleSearch.class). Here I got a NullpointerException.

FYI, I am using AEM 6.0.

Thanks

Nanda

Avatar

Employee

do you have a stacktrace in the error.log file?

Avatar

Level 10

Can you give me the usecase for adapting SimpleSearch ?