请帮助我,我做错了什么
InfraNameModel
public interface InfraNameModel {
String getInfraName();
void setInfraName(String infraName);
}
InfraNameModelImpl
public class InfraNameModelImpl implements InfraNameModel {
private String infraName;
@Override
public String getInfraName() {
return infraName;
}
@Override
public void setInfraName(String infraName) {
this.infraName = infraName;
}
}
InfraNameModelList
public interface InfraNameModelList<T extends InfraNameModel> {
public List<T> getInfraNameModelList();
public void setInfraNameModelList(List<T> infraNameModel);
}
InfraNameModelListImpl
public class InfraNameModelListImpl implements InfraNameModelList<InfraNameModel> {
private List<InfraNameModel> infraNameModelList;
@Override
public List<InfraNameModel> getInfraNameModelList() {
return infraNameModelList;
}
@Override
public void setInfraNameModelList(List<InfraNameModel> infraNameModelList) {
this.infraNameModelList = infraNameModelList;
}
}
IBeanFactory
public interface IBeanFactory extends AutoBeanFactory {
IBeanFactory INSTANCE = GWT.create(IBeanFactory.class);
AutoBean<InfraNameModel> infraNameModel();
AutoBean<InfraNameModelList> infraNameModelList();
}
...
InfraNameModelList infraNameModelList = beanFactory.deserializeFromJson(" [{\"infraName\":\"TEST1\"},{\"infraName\":\"TEST2\"}}");
if (infraNameModelList == null)
logger.info("infraNameModelList=== null");
else
logger.info("infraNameModelList not null " + infraNameModelList);
List<InfraNameModelImpl> infraNameModel = infraNameModelList.getInfraNameModelList();
if (infraNameModel == null)
logger.info("infraNameModel=== null");
else
logger.info("infraNameModel=== not null " + infraNameModel);
InfraNameModelImpl infraNameModelImpl = infraNameModel.get(0);
if (infraNameModel == null)
logger.info("infraNameModelImpl=== null");
else
logger.info("infraNameModelImpl=== not null " + infraNameModelImpl);
logger.info("===" + infraNameModelImpl.getInfraName());
所以我有这样的错误 在这一行
ConsoleLogger.java:32 infraNameModel === null
为什么infraNameModel为null ??? =(
===SUCCESS
ConsoleLogger.java:32 ===[{"infraName":"TEST1"},{"infraName":"TEST2"}]
ConsoleLogger.java:32 infraNameModelList not null by.client.models.infraNameModel.InfraNameModelListAutoBean$2@36
ConsoleLogger.java:32 infraNameModel=== null
ConsoleLogger.java:32 (TypeError) : Cannot read property 'get_18_g$' of null
H3f_g$ @ ConsoleLogger.java:32
eAf_g$ @ SimpleConsoleLogHandler.java:36
szf_g$ @ Logger.java:312
rzf_g$ @ Logger.java:302
Pzf_g$ @ Logger.java:236
rad_g$ @ LogConfiguration.java:169
lab_g$ @ Impl.java:186
$9_g$ @ Impl.java:293
(anonymous) @ Impl.java:77
ConsoleLogger.java:55 Exception: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read property 'get_18_g$' of null
ConsoleLogger.java:32 TypeError: Cannot read property 'get_18_g$' of null
at uHg_g$.D$g_g$ [as onSuccess_8_g$] (Configuration.java:71)
at uHg_g$.xHg_g$ [as onSuccess_1_g$] (Configuration.java:55)
at S9f_g$.Ny_g$ [as onResponseReceived_0_g$] (AbstractRequestCallback.java:94)
at ZLc_g$.aMc_g$ [as fireOnResponseReceived_0_g$] (Request.java:250)
at hNc_g$.iNc_g$ [as onReadyStateChange_0_g$] (RequestBuilder.java:412)
at XMLHttpRequest.<anonymous> (XMLHttpRequest.java:329)
at X9_g$ (Impl.java:239)
at $9_g$ (Impl.java:291)
at XMLHttpRequest.<anonymous> (Impl.java:77)
答案 0 :(得分:1)
为什么infraNameModel为null ??? =(
因为数组没有infraNameModelList
属性。
您必须将JSON数组包装到具有此类属性的对象中,以使其与您的AutoBean模型匹配。