aspose file tools*
The moose likes Beginning Java and the fly likes Class conversion to string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Class conversion to string" Watch "Class conversion to string" New topic
Author

Class conversion to string

BHAVESH SHA
Greenhorn

Joined: Jun 07, 2007
Posts: 15
Respected Sir,

I have created one package where hierarchy of class starts from Application below that class i have created other two classes i.e. call A and B,

Now When i m trying to execute A and B classes in Application class and trying to convert into string but it is giving me error type mismatch so can you please share method which would solve my problem

Looking forward for your favourable reply soon

Regards

Bhavesh Shah
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3654
    
  15
I don't quite understand your question. Can you post some code (using code tags) and explain exactly what you are trying to convert into a string.


Joanne
BHAVESH SHA
Greenhorn

Joined: Jun 07, 2007
Posts: 15
Dear Sir ,
I have package named model in which
Top level Class Application and other two classes are below it
i.e Applicant,Deviation

code :
public class Application implements Serializable, ComparisionDifferencesCollector {
private Applicant[] applicants;
private Deviation[] deviations;

public Applicant[] getApplicants() {
return applicants;
}
public void setApplicants(Applicant[] applicants) {
this.applicants = applicants;
}
...
}

public class TestParser {
public static void main(String args[]){
APSBusinessDataDAO buildApplicationDAO = new APSBusinessDataJDBCImplementation();
Application application = buildApplicationDAO.buildApplication("51715486");
String applicant= application.getApplicants();
String deviation= application.getDeviation().

I required to convert applicant to String format as it shows the error:
Type mismatch: cannot convert from Applicant[] to String

Kindly suggest for the same .
Thanks and regards
Bhavesh Shah
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

hi,

1. you was trying to convert array object to string.you can not do it..
directly..you need to type cost and you have to assign it to an array String.

String[] str=(String[])Object[]

you try with this concept

thanks & regards,
seetharaman
BHAVESH SHA
Greenhorn

Joined: Jun 07, 2007
Posts: 15
Hi,
Thanks for help , i tried your code
i.e
String[] applicant = ((String[])application.getApplicants());(in main class)
but error show
Cannot cast from Applicant[] to String[].

Kindly suggest it i have integrated wrong place .

Waiting for your reply
Thanks and Regards,.

Bhavesh Shah
pavan kumar seeram
Greenhorn

Joined: Nov 21, 2007
Posts: 7
why cant you try this............
String[] applicant = (application.getApplicants().toString());
qingwu wang
Ranch Hand

Joined: Feb 19, 2003
Posts: 147
If you want to do that, you have much work to do.
You can add a method invoke your get method and translate to String array type.


Thanks...qingwu<br />When I open my eyes,I see your pretty face.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Class conversion to string