Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Java by redalin ( 13 years ago )
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) {
         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 + "]";
      }
 }
    

}

 

Revise this Paste

Parent: 52291
Your Name: Code Language: