1
I m XML을 java 모델로 구문 분석합니다. xml을 Java Object로 파싱하는 동안 com.thoughtworks.xstream.mapper.CannotResolveClassException 예외가 발생합니다. 여기 내 코드가있다. http 응답에서 xml을 받고 있습니다. 그리고 난 자바 모델 여기안드로이드의 com.thoughtworks.xstream.mapper.CannotResolveClassException
public class GetCarAsynTask extends AsyncTask<Void,Void,HttpResponse> {
private Context mContext;
private String mApiID;
private String mApikey;
private List<Car> list;
public GetCarAsynTask(Context context, String apiID, String apikey) {
mContext = context;
mApiID = apiID;
mApikey = apikey;
}
@Override
protected HttpResponse doInBackground(Void... params) {
HttpResponse httpResponse = null;
try {
String xmlData = XmlConverter.convertStreamToString(mContext.getAssets().open(ConstantsUtils.GET_CAR_FILE_NAME));
xmlData = String.format(xmlData, mApiID, mApikey);
httpResponse = WebServiceUtils.getCar(xmlData);
list = getCar(httpResponse);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return httpResponse;
}
private List<Car> getCar(HttpResponse response) {
List<Car> list;
try {
if (response != null) {
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
XStream xstream = new XStream();
xstream.alias("Car", Car.class);
xstream.setClassLoader(Car.class.getClassLoader());
list = (List<Car>) xstream.fromXML(is);
//list = XmlPullParserHandler.getInstance().parse(is);
return list;
}
}
} catch (Exception e) {
Log.i("car", "error");
}
return null;
}
}
로 변환 할 것은 XML
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
<soap:Body>
<GetCarsResponse>
<GetCarsResult>
<ResponseCode>0</ResponseCode>
<ResponseText>OK</ResponseText>
<Cars>
<Car>
<CarId>18</CarId>
<CarCode>NHO 314</CarCode>
<CarName>paddy</CarName>
<CarType>8 PAX LIMO</CarType>
</Car>
<Car>
<CarId>19</CarId>
<CarCode>NHO 352</CarCode>
<CarName />
<CarType>8 PAX LIMO</CarType>
</Car>
<Car>
<CarId>20</CarId>
<CarCode>NHO 382</CarCode>
<CarType>A CLASS</CarType>
</Car>
<Car>
<CarId>21</CarId>
<CarCode>NHO 417</CarCode>
<CarName />
<CarType>8 PAX LIMO</CarType>
</Car>
</Cars>
</GetCarsResult>
</GetCarsResponse>
</soap:Body>
</soap:Envelope>