This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes CAST question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "CAST question" Watch "CAST question" New topic
Author

CAST question

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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;
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
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

Joined: Jun 21, 2005
Posts: 386

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.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
You can't cast an Object to a primitive.
You can use the intValue() method in the BigInteger class to get the integer value.



Mani
Quaerendo Invenietis
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CAST question
 
Similar Threads
Deafult behaviour of EJB Container Managed Transaction
Unreachable code question
Purchased WHIZLABS kit, But not able to see now
Help, please - conversion problem
How to Achive Transaction Concurrency in EJB 3