이 방법이 있습니다. 문제는이 조건이catch 블록이 호출 된 경우에도 코드가 실행 중입니다.
if (bagList==null||bagList.size()<1 && UngarList==null||UngarList.size()<1)
을 충족 될 때 그것은 여기 catch 블록에
catch (Exception e) {
this.errorText = e.getMessage().toString();
info.setErrorText(this.errorText.toString());
response.setinfo(info);
}
을 것입니다하지만 여전히
final boolean toProceedorNot = validate(bagList.toArray(new Bag[bagList.size()]))
입니다 다음 줄을 execuing 것이 무엇인지 이것이 맞는다면 원하는가이다.
if (bagList==null||bagList.size()<1 && UngarList==null||UngarList.size()<1)
**then directly return the response;**
이
public Response getData(Request request) {
Info info = new Info();
Response response = new Response();
String xmlrequest = request.getxmlMessage();
HashMap listMap = new HashMap();
List<Ungar> UngarList = new ArrayList<Ungar>();
List<Bag> bagList = new ArrayList<Bag>();
UniverseStaxParser xmlparser = new UniverseStaxParser();
try {
listMap = (HashMap) xmlparser.parseData(xmlrequest);
UngarList = (List<Ungar>) listMap.get("UngarItems");
bagList = (List<Bag>) listMap.get("bagItems");
if (bagList==null||bagList.size()<1 && UngarList==null||UngarList.size()<1)
throw new Exception("No Valid Data is passed as Input ");
} catch (Exception e) {
this.errorText = e.getMessage().toString();
info.setErrorText(this.errorText.toString());
response.setinfo(info);
}
final boolean toProceedorNot = validate(bagList.toArray(new Bag[bagList.size()]));
try {
if (!toProceedorNot) {
info.setErrorText(errorText);
response.setinfo(info);
} else {
// some logic here goes
}
} catch (Exception e) {
errorText = e.getMessage().toString();
info.setErrorText(errorText);
response.setinfo(info);
}
return response;
}
null 객체의 메소드를 호출하면 널 포인터 예외가 발생합니다. 이것은 일반적인 실수입니다. – Jasonw
대단히 고맙습니다. 코드를 수정하여 하나의 try 블록 아래에 보관했습니다. 이제는 작동합니다. – Revathi