• 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

CAST question

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a problem in my BOLDED code below whereby I am trying to convert a BIGINTEGER to an INT. Any direction or help would be appreciated. Here is my code:

// Check request version against response header version.
int responseVersion;
responseVersion = (int)responseheader.getVersion();
if (
//responseheader.getVersion().compareTo(
responseVersion.compareTo(
beginTransactionRequest.getHeader().getVersion()
) = 0
)

{
Transaction transaction = new Transaction();
response.setTransactionID(BigInteger.valueOf(transaction.GetId()));
}else{
responseheader.setStatus(Status.fromString("VersionNotSupported"));
}
return response;
 
Ranch Hand
Posts: 1071
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
responseVersion is not a BigInteger it is an int so it has no compareTo method.

What does the getVersion method return?
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steven,

Thanks for the reply. The getVersion method returns a BigInteger but I need to CAST that to an INT as well so I guess I should have put a (INT) in front of the second half of my assignment(?).

Sorry, still new to Java.

Regards.
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't cast an Object to a primitive.
You can use the intValue() method in the BigInteger class to get the integer value.

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Mani.

Appreciate the help. That got it. Sorry, I should have looked at the API first.
[ July 06, 2005: Message edited by: Melinda Savoy ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic