0

I get ClassCastException in Logcat at this line: Standort standort = (Standort) response;

From this code:

private void loadLocationMenuList() {
    ServiceProxy.createWebServiceTask(getActivity(), new RemoteCallListener() {

            @Override
        public void onRemoteCallError(String response) {
            // TODO Auto-generated method stub

       }

        @Override
        public void onRemoteCallComplete(Object response) {
            Log.d("debug", "response is = "+response+"\t"+response.getClass()); 
            Standort standort =  (Standort) response;
            locationMenuAdapter = new LocationMenuAdapter(StandorteFragment.this, standort);
            menuItemListLoc.setAdapter(locationMenuAdapter);
        }

        @Override
        public void onNoInternetError() {
            // TODO Auto-generated method stub
        }

        @Override
        public void onNoAccess() {
            // TODO Auto-generated method stub
        }
    }, true).invokeGetStandorte();
}

Service Proxy:

public class ServiceProxy {

    private static final boolean useFakeService = true;

    public static IWebServiceTask createWebServiceTask(Context ctx, RemoteCallListener listener, boolean hasInternet) {
        //if (useFakeService) {
        return new FakeService(ctx, listener);
    }
}

FakeService:

public class FakeService extends CallWebServiceTask {

    private final boolean hasInternet = true;

    public FakeService(Context ctx, RemoteCallListener listener) {
        super(ctx, listener);
    }

    @Override
    protected WebEntityInterface doInBackground(CallWebServiceTask.InputParam... params) {
        System.currentTimeMillis();
        WebEntityInterface result = null;
        CallWebServiceTask.InputParam param = null;
        param = params[0];
        if (param.url.startsWith(Constants.invokeGetStandorte)) {
            return super.doInBackground(params);
        }
        try {
            if (hasInternet) {
                if (param.CALL_TYPE == InputParam.GET) {
                    result = sendGET(param);
                } else if (param.CALL_TYPE == InputParam.POST) {
                    result = sendPOST(param);
                }
            } else {
                LogService.log("CALL WEBSERVICE TASK", " NO INTERNET!!!!");
                result = new WebEntity(1, "No internet connection!");
            }
        } catch (UnknownHostException e) {
            LogService.err("WEB-SERVER-ERROR", e.getMessage(), e, LogService.LOG_LEVEL_FULL);
            result = new WebEntity(1, "No internet connection!");
        } catch (SocketException e) {
            LogService.err("WEB-SERVER-ERROR", e.getMessage(), e, LogService.LOG_LEVEL_FULL);
            result = new WebEntity(1, "No network connection!");
        } catch (Throwable e) {
            LogService.err("WEB-SERVER-ERROR", e.getMessage(), e, LogService.LOG_LEVEL_FULL);
            result = new WebEntity(2, "Network connection error!");
        }
        return result;
    }

    @Override
    public WebEntityInterface sendGET(CallWebServiceTask.InputParam param) throws Exception {
        if (param.url.startsWith(Constants.invokeGetStandorte)) {
            return super.sendGET(param);
        }
        SessionToken.Sessiontoken = "dfasmdfnasdfb";
        System.out.println("-----GET[" + param.clazz + "] : " + param.url);
        WebEntityInterface result = null;
        Populator populator = new Populator(new RandomDriver());
        result = populator.fill(param.clazz);
        result.setSuccess(true);
        System.out.println("------------RESULT :" + result);
        return result;
    }

    @Override
    public WebEntityInterface sendPOST(CallWebServiceTask.InputParam param) throws Exception {
        if (param.url.startsWith(Constants.invokeGetStandorte)) {
            return super.sendPOST(param);
        }
        SessionToken.Sessiontoken = "dfasmdfnasdfb";
        System.out.println("-----POST : " + param.url);
        WebEntityInterface result = null;
        Populator populator = new Populator(new RandomDriver());
        result = populator.fill(param.clazz);
        result.setSuccess(true);
        System.out.println("------------RESULT :" + result);
        return result;
    }

}

My LocationMenuAdapter:

public class LocationMenuAdapter extends BaseAdapter {
    private LayoutInflater mInflater;
    private AQuery aQuery;
    private Standort standort;
    private StandorteFragment standorteFragment;

    public LocationMenuAdapter(StandorteFragment standorteFragment, Standort standort) {
        this.standorteFragment  =standorteFragment;
        this.standort  =standort;
        this.aQuery = standorteFragment.aQuery;  
        mInflater = LayoutInflater.from(standorteFragment.getActivity());
    }

    public int getCount() {
        return standort.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public StandortItem getEKUrl(int i) {
        return standort.get(i);
    }

    public View getView(int position, View convertView, ViewGroup parent) { 
        ListContent holder;
        StandortItem standortItem = getEKUrl(position);
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.listviewinflate, null);
            holder = new ListContent();
            holder.text = (TextView) convertView.findViewById(R.id.TextView01);
            convertView.setTag(holder);
        } else {
            holder = (ListContent) convertView.getTag();
        }

        holder.text.setText(standortItem.Name);
        return convertView;
    }

    class ListContent {
        TextView text;

    }
}

AND LAST BUT NOT LEAST: The WebEntity:

public class Standort extends WebEntity {
    public static int IDtest;
    public ArrayList<StandortItem> standort = new ArrayList<StandortItem>();

    public void add(StandortItem standortItem) {
        standort.add(standortItem);
    }

    public int size() {
        return standort.size();
    }

    public StandortItem get(int i) {
        return standort.get(i);
    }

    public class StandortItem implements Serializable{
        public Integer ID;
        public String Name;
        public String Strasse;
        public String Email;
        public Integer PLZ;
        public String Ort;
        public String Telefon;
        public String Fax;
        public String Oeffnungszeiten;
        public Boolean Bar;
        public Boolean BusinessLunch;
        public Boolean Parkplatz;
        public Boolean Raucher;
        public String GooglemapsStrasse;

        public StandortItem(Integer ID, String Name,String Strasse, String Email,Integer PLZ, String Ort,String Telefon, String Fax,String Oeffnungszeiten, Boolean Bar,Boolean BusinessLunch, Boolean Parkplatz,Boolean Raucher,String GooglemapsStrasse) {
            super();
            this.ID = ID;
            this.Name = Name;
            this.Strasse = Strasse;
            this.Email = Email;
            this.PLZ = PLZ;
            this.Ort = Ort;
            this.Telefon = Telefon;
            this.Fax = Fax;
            this.Oeffnungszeiten = Oeffnungszeiten;
            this.Bar = Bar;
            this.BusinessLunch = BusinessLunch;
            this.Parkplatz = Parkplatz;
            this.Raucher = Raucher;
            this.GooglemapsStrasse = GooglemapsStrasse;
            IDtest=ID;
        }

        public String toString() {
            return "Standort [ID=" + ID + ", Name=" + Name + ", Strasse=" + Strasse + ", Email=" + Email + ", PLZ=" + PLZ + ", Ort=" + Ort + ", Telefon=" + Telefon + ", Fax=" + Fax + ", Oeffnungszeiten=" + Oeffnungszeiten + ", Bar=" + Bar + ", BusinessLunch=" + BusinessLunch + ", Parkplatz=" + Parkplatz + ", Raucher=" + Raucher + ",GooglemapsStrasse=" + GooglemapsStrasse + "]";
        }
    }
}

The "Log.d("debug", "response is = "+response+"\t"+response.getClass())" line says the following:

 07-30 16:48:22.031: D/debug(25496): response is = [WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null], WebEntity [success=false, errorCode=0, errorMessage=null]]   class com.weinco.webservice.entity.Standorts

The Standorts class:

public class Standorts extends WebListEntity<Standort> {
    public Standorts() {
        super();
    }

}

PS: I didn't really work much with web services, so I'm kind of a beginner to this, so there could be parts of code that are not really correct written, if you can help on that too, I would be very grateful.

7
  • 1
    it's kinda obvious that you cannot cast the Object response into Standort. Try figuring out what the response is first, by using Logcat calls before casting... Commented Jul 30, 2012 at 13:42
  • what kind of Logcat Calls? and i have to figure out how the response looks like, so i would know how to call it into Standort:-? Commented Jul 30, 2012 at 13:43
  • Log.d(String logtag, String logMessage) one for instance. like Log.d("debug", "response is = "+response+"\t"+response.getClass()); etc... see who calls the method and what gets passed. once you figure out the incoming data, you'll know if it's your Standort or something else that'll help you rebuild the standort or whatever. Commented Jul 30, 2012 at 13:45
  • now i have no clue how to build my code, i had an idea, thought it's logical (after me) but as you can see in the newly editer LOGCAT log, i need some huge help Commented Jul 30, 2012 at 13:56
  • Looks like your response is an arrayList of WebEntities ... but at the end it states it's className as Standorts. So, try casting it into Standorts and then pulling each Standort from it. Commented Jul 30, 2012 at 14:04

2 Answers 2

1

so i guess something like this? i don't know what you're trying to do here really...

    @Override
    public void onRemoteCallComplete(Object response) {
        Log.d("debug", "response is = "+response+"\t"+response.getClass()); 
        Standorts standorts =  (Standorts) response;

        //to get individual Standort objects from this WebListEntity<Standort> wrapper you need

        //get WebEntity from standorts

        //do whatever you need to do to make a Standort object out of that.

        Standort standort = new Standort();
        standort.restoreFromWebEntity(theWebEntityYouGotInStepOne);

        locationMenuAdapter = new LocationMenuAdapter(StandorteFragment.this, standort);
        menuItemListLoc.setAdapter(locationMenuAdapter);
        }
    }

but the response you get is definatelly Standorts.

Look at this WebListEntity class as well... It's not the WebEntity you posted. In other words, all this code you posted except this function is somewhat useless.

Sign up to request clarification or add additional context in comments.

5 Comments

I'm going to try this. I have no ideea what I'm doing too. I knew what I was doing untill my boss gave me a lot of webservices entities, and he said that these we have to connect to the project (and not the ones that i have) and this entities come with a PDF about them, in german, and I don't know german, and even if i knew it's somewhat useless. And thats how i got lost in translation
well, at least it seems like you're back on the track ;) now you know what you're getting in the function call and the problem boils down to getting each Standort item from this WebListEntity (which extends ArrayList?) i'm just trying to picture a diagram here and all i see is a big mess with mixed english/german fields all over it :D seems like someone wanted to keep his job.
offtopic: thc.org/root/phun/unmaintain.html it just seems really relevant.
if you're having problems with lists and adapters then this might be of relevance as well stackoverflow.com/questions/11722885/… but from what i see, the adapter looks good.
10x, but they work. At least they worked perfect before webservices, and i haven't changed them since.
0

I manage to make it work somehow by using the weblistentity class Standorts as the list where the adapter inflated the webentities (Standort).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.