0
在我java
代码,我有下面的类使用时有一个空值,我看到了我的用户ID - 这很好。为什么从父类确实实地在其他类(Java/Apache的吊索)
现在我需要编写一个扩展上面的第二个类。它看起来像这样:
public class MyNextListModel extends ListModel{
//this method throws nullpointer because resourceResolver is null - why?
@Override
public List<ListItemModel> getAllItems() {
System.out.println(resourceResolver.getUserID());
}
}
为什么第二个类中的resourceResolver有一个空值?
我也尝试移动此代码:从ListModel
@Inject
protected ResourceResolver resourceResolver;
到MyNextListModel
,但即便如此,它仍然是空的二等
你试过super.resourceResolver.getUserID()吗? –
凯尔,我试过了,它不工作,不幸的是... – randomuser1
我现在没有办法检查这个,但我相信Sling需要子类本身用'@ Model'注释进行注释。它不是在超级课堂上寻找它。尝试添加'@Model(adaptables = SlingHttpServletRequest.class)'到'MyNextListModel'。 – toniedzwiedz