java.lang.string无法强制转换为java.util.Vector

时间:2014-07-16 06:47:16

标签: java arraylist

我无法弄清楚这一点。我的代码抛出了这个错误

  

java.lang.ClassCastException:java.lang.String无法强制转换为java.util.Vector    .WebService.parseJourney

    public static ArrayList<Journey> parseJourney(Object response) {
      ArrayList<Journey> rs = new ArrayList<Journey>();
      try {
        if (response == null) {
            return rs;
        }
    @SuppressWarnings("unchecked")
    Vector<Object> result = (Vector<Object>) response;
        if (result.size() < 4) {
            return rs;
        }

我肯定使用过仿制品,过去没有任何问题。

哇 - 这很快。 对parseJourney的调用:

    Vector<EntryValue> values = new Vector<EntryValue>();
    EntryValue value = new EntryValue();

    SoapObject request = new SoapObject(NAMESPACE_ENTRY, METHOD_NAME_ENTRY);
    PropertyInfo pi = new PropertyInfo();
    pi.setName("values");
    pi.setValue(values);
    pi.setType(MyArrayList.class);

    request.addProperty(pi);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    envelope.dotNet = true;
    HttpTransportSE aht = new HttpTransportSE(URL_ENTRY);
      try {
          aht.call(SOAP_ACTION_ENTRY, envelope);
          Object response = envelope.getResponse();
          resultEntry = parseJourney(response);
          return response.toString();
          } 
      catch (Exception e) {
    ERROR_EXCEPTION = 1;
    return e.toString();
     }
    }

2 个答案:

答案 0 :(得分:0)

parseJourney()收到一个String,你试图将它转换为Vector而不进行测试

if(response instanceof Vector)
{
   Vector<Object> result = (Vector<Object>) response;
   //...
}

并且不要放@SuppressWarnings("unchecked"),这通常是一种不好的做法

答案 1 :(得分:-1)

传递给parseJourney()的对象是String,而不是Vector。如果您需要更多信息,则需要包含任何代码调用parseJourney()