在这里我没有数据,然后我得到了 Pcode 0,但在这里我无法得到 Pcode 0,我的意图是让 Pcode 为零并显示“此处没有数据”消息。我已经使用 xml 进行数据解析,但不能正确,我有解析错误,但无法找到,我在哪里出错。这是我的代码:
Log.d("user id is ", userId + "!");
String input = String.format("<Es_Request><Data><UserId>%s</UserId></Data></Es_Request>", userId);
String response = HttpPostRetreiver .retriver(Url.url_getting_assignment, input, GradeAssignmentActivity.this);
if (response != null) {
esResponse = XmlParser.parseAssignmentProfessorResponse(response);
Log.d("TAG", "Checking Value="+ esResponse.getResponseCode().getpCode());
if (esResponse.getResponseCode().getpCode().equalsIgnoreCase("1")) {
assignmentDataInfo = esResponse .getAssignmentListData().getAssignmentDataInfo();
int size = assignmentDataInfo.size();
int i = 0;
for (; i < size; i++) {
EduInterface.assignmetIdArrayList.add(assignmentDataInfo.get(i).getAssignmentId());
EduInterface.assignmetNameArrayList.add(assignmentDataInfo.get(i).getAssignmentName());
}
} else {
test = 1;
Log.d("else", "Not data Here");
}
}
} else {
Log.d("TAG", "Error in Webservice");
}
} catch (Exception e) {
Log.e("Grade Assignment class", e.toString() + "");
}
我有,第一个用户ID是5!然后得到错误等级分配类错误。我一直在解析问题这里是paing>
输入字符串: Es_Request><Data><UserId>913</UserId></Data></Es_Request>
响应字符串:
<?xml version="1.0" encoding="utf-8"?><Es_Response><Es_Session_Id></Es_Session_Id>
<Bpn_Request_Id></Bpn_Request_Id><Response_Code><Pcode>0</Pcode><Scode>Unsuccessful</Scode></Response_Code><Data><message>Assignments not found for Professor & CourseId.</message></Data></Es_Response>
这是我的处理程序类:
@Override
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
content = new StringBuilder();
if (localName.equalsIgnoreCase("Data")) {
assignmentListData=new AssignmentListData();
} else if (localName.equalsIgnoreCase("assignments")) {
assignmentItems = new AssignmentItems();
}
else if (localName.equalsIgnoreCase("Es_Response")) {
esResponse=new EsResponse();
} else if (localName.equalsIgnoreCase("Response_Code")) {
responseCode=new ResponseCode();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("Pcode")) {
responseCode.setpCode(content.toString());
Log.d("TAG", "Pcode Value->"+content.toString());
}
else if (localName.equalsIgnoreCase("Response_Code")) {
esResponse.setResponseCode(responseCode);
}
else if (localName.equalsIgnoreCase("AssignmentId")) {
assignmentItems.setAssignmentId(content.toString());
}
else if (localName.equalsIgnoreCase("AssignmentName")) {
assignmentItems.setAssignmentName(content.toString());
}
else if (localName.equalsIgnoreCase("Assignments")) {
assignmentDataInfo.add(assignmentItems);
}
else if (localName.equalsIgnoreCase("Data")) {
assignmentListData.setAssignmentDataInfo(assignmentDataInfo);
}
else if (localName.equalsIgnoreCase("Es_Response")) {
esResponse.setAssignmentListData(assignmentListData);
}
}
我得到了 logcat:
04-30 19:25:51.378: D/getting course list->(1598): Line 322---RESPONSE<?xml version="1.0" encoding="utf-8"?><Es_Response><Es_Session_Id></Es_Session_Id>
04-30 19:25:51.378: D/getting course list->(1598): <Bpn_Request_Id></Bpn_Request_Id><userIDName>913</userIDName><schoolID>1</schoolID><CourseID>977</CourseID><Response_Code><Pcode>0</Pcode><Scode>Unsuccessful</Scode><Test>977</Test><ROLE ID>4</ROLE ID></Response_Code><Data><message>Assignments not found for Professor & CourseId.</message></Data></Es_Response>
04-30 19:25:51.378: D/user id is(1598): 913
04-30 19:25:51.378: D/school id is(1598): 1
04-30 19:25:51.388: D/TAG(1598): Pcode Value->0
04-30 19:25:51.398: W/System.err(1598): org.apache.harmony.xml.ExpatParser$ParseException: At line 2, column 189: not well-formed (invalid token)
04-30 19:25:51.398: W/System.err(1598): at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:499)
04-30 19:25:51.398: W/System.err(1598): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:484)
04-30 19:25:51.409: W/System.err(1598): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:309)
04-30 19:25:51.409: W/System.err(1598): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:267)
04-30 19:25:51.409: W/System.err(1598): at sdei.edustatusnew.services.XmlParser.parseAssignmentProfessorResponse(XmlParser.java:840)
04-30 19:25:51.409: W/System.err(1598): at sdei.edustatusnew.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:326)
04-30 19:25:51.409: W/System.err(1598): at sdei.edustatusnew.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:1)
04-30 19:25:51.427: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.427: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.438: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.438: W/Trace(1598): Unexpected value from nativeGetEnabledTags: 0
04-30 19:25:51.468: W/System.err(1598): at android.os.AsyncTask$2.call(AsyncTask.java:287)
04-30 19:25:51.478: W/System.err(1598): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
04-30 19:25:51.478: W/System.err(1598): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
04-30 19:25:51.488: W/System.err(1598): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
04-30 19:25:51.488: W/System.err(1598): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
04-30 19:25:51.488: W/System.err(1598): at java.lang.Thread.run(Thread.java:856)
04-30 19:25:51.488: E/Grade Assignment class(1598): java.lang.NullPointerException
请您帮忙,我的代码有什么错误。提前致谢。