• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

toString or String.valueOf()

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have declared the following values as int and double but my problem is that I�ve created an array which returns a string which means since Prefnum is declared as an int then it will have to be converted to a string, now do I used String.valueOf or toString to convert so I can print out these values as strings? The error that i'm getting when using either one of the two is incompatible data type.

thanks


int Prefnum=0;
int Arefnum=0;
int Pserial=0;
double Pvalue=0;

try {

String[] proceedingsList=crime.getProceedingsDetails(conn,referenceNumber);
// Prefnum=String.valueOf(proceedingsList[0]);
// Prefnum=(proceedingsList[0]).toString();

Prefnum=proceedingsList[0]);
if(proceedingsList[0]==null){
Prefnum="";
}else{
Prefnum=(proceedingsList[0]);
}

Ptype=proceedingsList[1];
if(proceedingsList[1]==null){
Ptype="";
}else{
Ptype=proceedingsList[1];
}
Pserial=proceedingsList[2];
if(proceedingsList[2]==null){
Pserial="";
}else{
Pserial=proceedingsList[2];
}
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you tell me what the error you got is?
 
Kingsley Mullers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm getting "incompatible type; found: java.lang.String,required: int" error.

thanks
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Either "String.valueOf(Prefnum)" or "(new Integer(Prefnum)).toString()" should work.
 
Kingsley Mullers
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've tried it like this...

String Prefnum;

Prefnum=Integer.parseInt(proceedingsList[0]).toString(); //incompatible type

and also tried

int Prefnum=0;
Prefnum=String.valueOf(proceedingsList[0]); //incompatible type

what am i missing here?

thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Integer.parseInt takes a String as parameter, not an int, and it returns an int, which is not an object, and thus does not have a toString method.

2) String.valueOf returns a String, not an int.

Try
int Prefnum = Integer.parseInt(proceedingsList[0]);

If you're in doubt what kind of parameter a method accepts, or what kind of value it returns, you can check the javadocs for java.lang.Integer and java.lang.String.
[ August 29, 2005: Message edited by: Ulf Dittmer ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic