Issues with SCR References
I'm trying to utilize a reference to the QueryBuilder within a maven bundle, but I'm getting a Null Pointer Exception when I execute any methods on the Object that is injected. My maven install doesn't seem to throw any relevant errors or warnings, in fact within the web console, the entry for my bundle is listed under the "using bundles" section of the com.day.cq.Search service.
Trying the same method calls with other services (ResourceResolverFactory for example) generates the same null pointer exception. The line referenced in the stack trace is on the method call within the method of my class im working in, not on the @reference in my class.
com.uc.news.Author.(Author.java:64)
I'm not sure if this is an issue with binding/unbinding, but I believe those methods are being set automatically--I've double checked that I have the latest version f all the decencies set up n my POM.xml (from the adobe repos). Any guidance is appreciated.
Here's the top part of my Author Class (I'm developing a system for news publishing for our org) up until the line that throws the exception. (not that I'm passing the session to the constructor, which is how I got around the issue earlier before I fully understood what was occurring).
package com.uc.news; import org.apache.felix.scr.annotations.*; import javax.jcr.Value; import javax.jcr.ValueFactory; import javax.jcr.Session; //for querying import com.day.cq.search.*; import com.day.cq.search.result.Hit; import com.day.cq.search.result.SearchResult; import java.util.HashMap; import java.util.Map; //Sling Imports import org.apache.sling.api.resource.ResourceResolverFactory; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.Resource; //Jackrabbit User APIs import org.apache.jackrabbit.api.JackrabbitSession ; import org.apache.jackrabbit.api.security.user.Group; import org.apache.jackrabbit.api.security.user.UserManager; import org.apache.jackrabbit.api.security.user.User; import org.apache.jackrabbit.api.security.user.Authorizable; @Component public class Author { @Reference private QueryBuilder queryBuilder; //Inject a Sling ResourceResolverFactory public String name = ""; public String id = ""; public String email = ""; public String phone = ""; public String title = ""; public String aboutMe = ""; public String headshot = ""; public String reassign = ""; public String approvers = ""; public String approvees = ""; public boolean newContact = false; public Author() { } public Author(String u, UserManager um, Session sess) { id = u; try{ //query for approvees Map<String,String> map = new HashMap<String, String>(); map.put("path","/home"); map.put("type", "rep:User"); map.put("fulltext.relPath","profile/approvers"); map.put("fulltext",id); Query approveeQuery = queryBuilder.createQuery(PredicateGroup.create(map),sess); SearchResult result = approveeQuery.getResult(); for (Hit hit : result.getHits()) { approvees += hit.getPath(); }...