Expand my Community achievements bar.

SOLVED

Multifield Model Null pointer exception

Avatar

Level 2

Dear All,

 

We have implemented Multifield component along with Model using Resource.

But we are getting null pointer exception when we are trying to get use Resource object.

 

Core Class:

import org.apache.sling.models.annotations.Model;

import org.apache.sling.api.resource.Resource;

@Model(
adaptables = {Resource.class},
adapters = {MultifieldModel.class},
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class MultifieldModelImpl implements MultifieldModel {

@inject
Resource componentResource;

public List<Map<String, String>> getDetailsWithMap() {
List<Map<String, String>> detailsMap=new ArrayList<>();
try {
Resource detailfield=componentResource.getChild("nodename/path");

}

}

}

 

Multifield Interface :

public interface MultifieldModel {
String getFieldTitle();
List<Map<String,String>> getDetailsWithMap();
}

 

in component we using this by data sly:
data-sly-use.field="pathtoclass.MultifieldModel"

 

when we render pages using this Model componentResource(

reosurce object) is giving as null.

 

This same code is workign fine in Dev env in both author- publisher and in production authors but only giving error in Production publishers.

 

Request you please suggest things we can modify or check in pub to make it work.

 

Thanks in advance

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@NaziyaP 

Suggesting the below given the same code is working fine in DEV and PROD author. 

  • Cross check if the multifield resource is available/accessible from PROD publish instance.
    • If you have access to CRXDE, check the same or if its accidentally removed 
    • Can try replicating the page containing multifield component and check (PROD publish app server and in admin login, if possible)

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @NaziyaP ,

    Make it public specfier and then try it.

@inject
Public Resource componentResource

Kr,

Sanjay

Avatar

Correct answer by
Community Advisor

@NaziyaP 

Suggesting the below given the same code is working fine in DEV and PROD author. 

  • Cross check if the multifield resource is available/accessible from PROD publish instance.
    • If you have access to CRXDE, check the same or if its accidentally removed 
    • Can try replicating the page containing multifield component and check (PROD publish app server and in admin login, if possible)

Avatar

Level 2

Hello Vijayalakshmi_S,

 

Thank you for your reply.

 

We have checked that resource is present in crx but when we try to hit that page even with pub ip port it still gives us same error.

I have tried creating new page with multifield components and published the same all changes are reflecting fine but still only that component is not rendering and keep on giving null pointer exception.

 

Avatar

Community Advisor

@NaziyaP 

Can you confirm if you are accessing the Publish application server with admin login ?

If yes and there is no access related issue, compare the problematic resource with working resource to narrow down the cause.