Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help, please - conversion problem

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to compare the INTVALUE of a transaction ID in readRequest to a transaction ID in a hashtable and I get the following error:

Incompatible operand types int and Transaction

My problem code is as follows as :

Transaction transaction = new Transaction();
if (readRequest.getTransactionID().intValue() != transaction.get(readRequest.getTransactionID().intValue())){
responseheader.setStatus(Status.fromString("InvalidTransactionID"));
return response;
}

The method of the transaction object that I am using is at the end of the following:

public class Transaction {
static int TransactionId = 0;
static Hashtable Transactions = new Hashtable();
int Id;

// Constructor created to create & increment the TransactionID's and put
// into Transactions Hashtable.
public Transaction(){
this.Id = TransactionId++;
Transactions.put(new Integer(TransactionId), this);
}

// Method created to grab the TransactionId from the constructor.
public int GetId(){
return Id;
}

// Method created to GET transaction key from the Transactions hashtable.
public static Transaction get(int key){
return get(new Integer(key));
}
}

Any help or direction would be appreciated. Regards.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if (readRequest.getTransactionID().intValue() != transaction.get(readRequest.getTransactionID().intValue()))


Change the above to:

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran,

Thanks so much for your help. It is appreciated.

May I ask this question. Once I did what you suggested I got not an error but a warning stating the following:

The static method get(Object) from the type Transaction should be accessed in a static way

Is this something I need to worry about?

Thanks, again..
[ July 26, 2005: Message edited by: Melinda Savoy ]
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just that instead of:



you should write:



because the get method is static, and doesn't need an object to access it.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much for the help.

Regards.

Originally posted by Ulf Dittmer:
Just that instead of:



you should write:



because the get method is static, and doesn't need an object to access it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic