• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Class conversion to string

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
BHAVESH SHA
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why cant you try this............
String[] applicant = (application.getApplicants().toString());
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic