File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 387

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: 387

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: 387

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