java - While converting from String to Object getting Typecast Error -


following code executing , getting error on line 14

type mismatch: cannot convert string timelimit

timelimit timelimitvalues = timelimitvalues(clientcompanymarketmapid,                 productcatagory, productsubcatagory, supplierid);  string timelimitvalue = timelimitvalues.gettimelimitvalue(); string timelimittc = timelimitvalues.gettimelimittc(); timelimitvalues.getbooktraveldatetc(); string ispaymentenabledflag = timelimitvalues.getispaymentenbld(); string isexponbkdate = timelimitvalues.getisexponbkdate(); string timeexpirydate = null; timelimit expirydate = new timelimit();  if (ispaymentenabledflag.equals("y")) {     if (isexponbkdate.equals("y")) {         if (timelimittc.equals("days")) {             c.add(calendar.date, integer.parseint(timelimitvalue));             timeexpirydate = sdf.format(c.gettime());             expirydate = timeexpirydate;             system.out.println("expiry date:   " + timeexpirydate);          } 

please help/guide

timeexpirydate declared in code string. expirydate declared timelimit.

you have line

expirydate = timeexpirydate; 

which not compile because trying assign string reference timelimit reference.

you need write sort of conversion method takes string , creates timelimit it. can utility method somewhere or timelimit(string timerepresentation) constructor in timelimit class. example write

expirydate = new timelimit(timeexpirydate); 

or

expirydate = someclass.converttotimelimit(timeexpirydate); 

java not c++ (in case that's you're used to). java not automatically call "conversion" constructor c++ does. if have defined timelimit(string) constructor, java not auto-call conversion. need explicitly call it.

but in event, there no way assignment without you writing conversion method somewhere , calling it.