Android intent.putExtra java.lang.illegalArgumentException -


i have class called adviewed implements parcelable.

here code:

public class adviewed implements parcelable {      protected long timestamp;     protected string country, city, lat, lng, ad_id, poster_id, user_id, latlng;      public void hydrate(hashmap<string, ?> map){         method[] methodes = this.getclass().getmethods();         iterator = map.keyset().iterator();         while(it.hasnext()){             object key = it.next();             object value = map.get(key);             string values = value.tostring();              string method = "set" + key.tostring();              for(method methode : methodes){                 if(methode.getname().equals(method)){                     try{                         methode.invoke(adviewed.this,  values);                     }                     catch(invocationtargetexception e){                         e.printstacktrace();                     }                     catch(illegalaccessexception e){                         e.printstacktrace();                     }                 }             }         }     }      public adviewed(long timestamp1, string country1, string city1, string lat1, string lng1, string ad_id1, string poster_id1,                     string user_id1, string latlng1){         this.timestamp = timestamp1;         this.country = country1;         this.city = city1;         this.lat = lat1;         this.lng = lng1;         this.ad_id = ad_id1;         this.poster_id = poster_id1;         this.user_id = user_id1;         this.latlng = latlng1;     }      public adviewed(){         this.timestamp = 0 ;         this.country = "";         this.city = "";         this.lat = "";         this.lng = "";         this.ad_id = "";         this.poster_id = "";         this.user_id = "";         this.latlng = "";     }      public adviewed(hashmap<string, ?> map){         this.timestamp = 0;         this.country = "";         this.city = "";         this.lat = "";         this.lng = "";         this.ad_id = "";         this.poster_id = "";         this.user_id = "";         this.latlng = "";          if(!map.isempty()){             this.hydrate(map);             //erreurs = new arraylist();         }     }       @override     public int describecontents(){         return 0;     }      @override     public void writetoparcel(parcel dest, int flags){         dest.writelong(timestamp);         dest.writestring(country);         dest.writestring(city);         dest.writestring(lat);         dest.writestring(lng);         dest.writestring(ad_id);         dest.writestring(poster_id);         dest.writestring(user_id);         dest.writestring(latlng);     }      public static final parcelable.creator<adviewed> creator = new parcelable.creator<adviewed>(){         @override         public adviewed createfromparcel(parcel source) {             return new adviewed(source);         }          @override         public adviewed[] newarray(int size) {             return new adviewed[size];         }      };      public adviewed(parcel in){         timestamp = in.readlong();         country = in.readstring();         city = in.readstring();         lat = in.readstring();         lng = in.readstring();         ad_id = in.readstring();         poster_id = in.readstring();         user_id = in.readstring();         latlng = in.readstring();     }      public long gettimestamp() {         return timestamp;     }      public void settimestamp(long timestamp) {         this.timestamp = timestamp;     }      public string getcountry() {         return country;     }      public void setcountry(string country) {         this.country = country;     }      public string getcity() {         return city;     }      public void setcity(string city) {         this.city = city;     }      public string getlat() {         return lat;     }      public void setlat(string lat) {         this.lat = lat;     }      public string getlng() {         return lng;     }      public void setlng(string lng) {         this.lng = lng;     }      public string getad_id() {         return ad_id;     }      public void setad_id(string ad_id) {         this.ad_id = ad_id;     }      public string getposter_id() {         return poster_id;     }      public void setposter_id(string poster_id) {         this.poster_id = poster_id;     }      public string getuser_id() {         return user_id;     }      public void setuser_id(string user_id) {         this.user_id = user_id;     }      public string getlatlng() {         return latlng;     }      public void setlatlng(string latlng) {         this.latlng = latlng;     } } 

and have class adindeal derives adviewed. here code:

public class adindeal extends adviewed {      protected string qte, costperunit, totalcost, imgpath;     protected boolean oncommand, onacheteur, onvendeur;     protected int statutdeal;  public adindeal(adindeal adindeal){      myinflation(adindeal); }      public void myinflation(adindeal adindeal1){         this.setuser_id(adindeal1.user_id);         this.setcostperunit(adindeal1.getcostperunit());         this.setimgpath(adindeal1.getimgpath());         this.setonacheteur(adindeal1.isonacheteur());         this.setoncommand(adindeal1.isoncommand());         this.setonvendeur(adindeal1.isonvendeur());         this.setqte(adindeal1.getqte());         this.setstatutdeal(adindeal1.getstatutdeal());         this.settotalcost(adindeal1.gettotalcost());         this.setad_id(adindeal1.getad_id());         this.setcity(adindeal1.getcity());         this.setcountry(adindeal1.getcountry());         this.setlat(adindeal1.getlat());         this.setlng(adindeal1.getlng());         this.setlatlng(adindeal1.getlatlng());         this.setposter_id(adindeal1.getposter_id());         this.settimestamp(adindeal1.gettimestamp());     }      public adindeal(long timestamp1, string country1, string city1, string lat1, string lng1, string ad_id1, string poster_id1,                     string user_id1, string latlng1, string qte1, string costperunit1, string totalcost1){          super(timestamp1, country1, city1, lat1, lng1, ad_id1, poster_id1,                 user_id1, latlng1);          this.qte = qte1;         this.costperunit = costperunit1;         this.totalcost = totalcost1;         this.imgpath = "";         this.oncommand = false;         this.onacheteur = false;         this.onvendeur = false;         this.statutdeal = 0;     }      public adindeal(long timestamp1, string country1, string city1, string lat1, string lng1, string ad_id1, string poster_id1,                     string user_id1, string latlng1, string qte1, string costperunit1, string totalcost1, string imgpath1){          super(timestamp1, country1, city1, lat1, lng1, ad_id1, poster_id1,                 user_id1, latlng1);          this.qte = qte1;         this.costperunit = costperunit1;         this.totalcost = totalcost1;         this.imgpath = imgpath1;         this.oncommand = false;         this.onacheteur = false;         this.onvendeur = false;         this.statutdeal = 0;     }       public adindeal(long timestamp1, string country1, string city1, string lat1, string lng1, string ad_id1, string poster_id1,                     string user_id1, string latlng1, string qte1, string costperunit1, string totalcost1,                     string imgpath1, boolean oncommand1, boolean onacheteur1, boolean onvendeur1, int statutdeal1){          super(timestamp1, country1, city1, lat1, lng1, ad_id1, poster_id1,                 user_id1, latlng1);          this.qte = qte1;         this.costperunit = costperunit1;         this.totalcost = totalcost1;         this.imgpath = imgpath1;         this.oncommand = oncommand1;         this.onacheteur = onacheteur1;         this.onvendeur = onvendeur1;         this.statutdeal = statutdeal1;     }     public adindeal(){         super();         this.qte = "";         this.costperunit = "";         this.totalcost = "";         this.imgpath = "";         this.oncommand = false;         this.onacheteur = false;         this.onvendeur = false;         this.statutdeal = 0;     }      public adindeal(hashmap<string, ?> map){         super(map);         this.qte = "";         this.costperunit = "";         this.totalcost = "";         this.imgpath = "";         this.oncommand = false;         this.onacheteur = false;         this.onvendeur = false;         this.statutdeal = 0;     }      @override     public void writetoparcel(parcel dest, int flags){         super.writetoparcel(dest, flags);          dest.writestring(qte);         dest.writestring(costperunit);         dest.writestring(totalcost);         dest.writestring(imgpath);         dest.writeint(statutdeal);         dest.writebyte((byte) (oncommand ? 1 : 0));         dest.writebyte((byte) (onacheteur ? 1 : 0));         dest.writebyte((byte) (onvendeur ? 1 : 0));     }      public adindeal(parcel in){         super(in);          qte = in.readstring();         costperunit = in.readstring();         totalcost = in.readstring();         imgpath = in.readstring();         statutdeal = in.readint();         oncommand = in.readbyte() != 0;         onacheteur = in.readbyte() != 0;         onvendeur = in.readbyte() != 0;      }      public string getqte() {         return qte;     }      public void setqte(string qte) {         this.qte = qte;     }      public string getcostperunit() {         return costperunit;     }      public void setcostperunit(string costperunit) {         this.costperunit = costperunit;     }      public string gettotalcost() {         return totalcost;     }      public void settotalcost(string totalcost) {         this.totalcost = totalcost;     }      public string getimgpath() {         return imgpath;     }      public void setimgpath(string imgpath) {         this.imgpath = imgpath;     }      public boolean isoncommand() {         return oncommand;     }      public void setoncommand(boolean oncommand) {         this.oncommand = oncommand;     }      public boolean isonvendeur() {         return onvendeur;     }      public void setonvendeur(boolean onvendeur) {         this.onvendeur = onvendeur;     }      public boolean isonacheteur() {         return onacheteur;     }      public void setonacheteur(boolean onacheteur) {         this.onacheteur = onacheteur;     }      public int getstatutdeal() {         return statutdeal;     }      public void setstatutdeal(int statutdeal) {         this.statutdeal = statutdeal;     } } 

i have activity, let's call activitya. activitya use intent go activity (which call activityb).

here code activitya:

adindeal adindeal = new adindeal(111111111, "canada", "torronto", "43.620595", "-79.376129", "id1",  "poster_id1" , "user_id1", "43.620595, -79.376129", "10", "100", "1000", "imgpath1")  intent intent = new intent(activitya.this, activityb.class); intent.putextra("text1", "a small text"); intent.putextra("text2", adindeal);//if delete line have no problem startactivity(intent); 

here code activityb:

intent mintent = getintent();  if(mintent != null){   string mtext = mintent.getstringextra("text1");   adindeal madindeal = mintent.getparcelableextra("text2");   toast.maketext(this, madindeal.getqte(), toast.length_long).show(); } 

when compile , run code, illegalargumentexception.

depending on debugger, comes line:

adindeal madindeal = mintent.getparcelableextra("text2"); 

in activityb.

but found out problem in activitya @ line:

intent.putextra("text2", adindeal); 

why happening?


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -