Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm unable to figure this out. My code is throwing this error

java.lang.ClassCastException: java.lang.String cannot be cast to 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;
        }

Am sure have used generics with no issues in past.

Wow - that was quick. The call to 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();
     }
    }
share|improve this question
5  
response holds a string, apparently... can you show the call to parseJourney? –  codeling Jul 16 '14 at 6:49
    
Obviously you want to cast a String to a Vector: Vector<Object> result = (Vector<Object>) response;. response is a String (that's the compiler saying –  Eypros Jul 16 '14 at 6:50
    
Show us how parseJourney is called. –  Ted Hopp Jul 16 '14 at 6:50

2 Answers 2

up vote 0 down vote accepted

parseJourney() receives a String and you are trying to cast it to Vector without testing it

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

And don't put @SuppressWarnings("unchecked"), it's generally a bad practice

share|improve this answer
    
point taken about warnings. Am still getting to grips with java, no NSMuttableArray to utilize, will get testing and 'tick' answers, many thanks! –  Hegar20 Jul 16 '14 at 9:52

The Object that is being passed into parseJourney() is a String, not a Vector. If you want more information than that, you'll need to include whatever code calls parseJourney().

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.