我ClassCastException
在这一行进入 Logcat:Standort standort = (Standort) response;
从这段代码:
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();
}
服务代理:
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);
}
}
假服务:
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;
}
}
我的 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;
}
}
最后但并非最不重要的: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 + "]";
}
}
}
"Log.d("debug", "response is = "+response+"\t"+response.getClass())" 行说明如下:
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
标准类:
public class Standorts extends WebListEntity<Standort> {
public Standorts() {
super();
}
}
PS:我并没有真正使用Web服务,所以我是这方面的初学者,所以可能有部分代码写得不太正确,如果你也能提供帮助,我会非常感激。