aspose file tools*
The moose likes Java in General and the fly likes Object or String Problem. Need Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object or String Problem. Need Help!" Watch "Object or String Problem. Need Help!" New topic
Author

Object or String Problem. Need Help!

Anand Karia
Ranch Hand

Joined: Sep 25, 2004
Posts: 156

Can anybody tell me what is wrong into this code.

ERROR: Incompatible Type
Found : java.lang.Object
Required: java.lang.String

error occur at (iRow


////////////////
private void insertLedgerBalance(int iRow)
{
try{
if (optReceipts.isSelected())
{
String atCode = tbl_PettyReceipt.getValueAt(iRow, 0);
String atAmount = tbl_PettyReceipt.getValueAt(iRow, 3);
}

else if(optDeduction.isSelected())
{
for (int a = 0; a < tbl_PettyReceipt.getRowCount(); a++)
{
String atCode = tbl_PettyReceipt.getValueAt(iRow, 0);
String atAmount = tbl_PettyReceipt.getValueAt(iRow, 3);
}
}
}
catch(Exception e){
System.out.println(e);
}
}


Love is GOD and GOD is Love.
Anand Karia
IT Concretor.......
M/s. Anand Karia Concreting IT
Bikramjit Singh Bajwa
Ranch Hand

Joined: Nov 23, 2003
Posts: 39
Hi Ananad,
Please see correct code:


////////////////
private void insertLedgerBalance(int iRow)
{
try{
if (optReceipts.isSelected())
{
String atCode = (String)tbl_PettyReceipt.getValueAt(iRow, 0);
String atAmount = (String)tbl_PettyReceipt.getValueAt(iRow, 3);
}

else if(optDeduction.isSelected())
{
for (int a = 0; a < tbl_PettyReceipt.getRowCount(); a++)
{
String atCode = (String)tbl_PettyReceipt.getValueAt(iRow, 0);
String atAmount = (String)tbl_PettyReceipt.getValueAt(iRow, 3);
}
}
}
catch(Exception e){
System.out.println(e);
}
}
John Uhlig
Greenhorn

Joined: May 12, 2003
Posts: 13
Anand - the previous post corrected your code but didn't tell you why it is correct. I am presuming that tbl_PettyReceipt is some sort of collection. When you put something into a collection, it is casted up to an Object. So, when you pull it out, you have an Object reference, even though the underlying object is actually a String. So, it has to be cast to a String before it can be assigned to the atCode or atAmount variable. Makes sense?

John
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Hi, All -

Please use the CODE UBB codes when posting code snippets. Doing so makes reading the code much easier as it preserves the indentation.

Thanks!


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Object or String Problem. Need Help!