aspose file tools*
The moose likes Beginning Java and the fly likes cast argument '0' to 'short' error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cast argument Watch "cast argument New topic
Author

cast argument '0' to 'short' error

sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 282
if (myRow.getCell(0) != null && myRow.getCell(0).toString()!="" && myRow.getCell(0)!=headings.get(0) && myRow.getCell(0)!=headings.get(1) && myRow.getCell(0)!=headings.get(2))

above line is giving error like

cast argument '0' to 'short'

when I run in jdk 1.5 project.

on all getCell(0) methods of above line.

same code worked fine when I ran the file in one other project that is running on jdk 1.4.

when i cast it like below

if (myRow.getCell((short) 0) != null && myRow.getCell((short) 0).toString()!="" && myRow.getCell((short) 0)!=headings.get(0) && myRow.getCell((short) 0)!=headings.get(1) && myRow.getCell((short) 0)!=headings.get(2)){

it is printing like unclear object not the cell values.

org.apache.poi.hssf.usermodel.HSSFCell@95fd19 org.apache.poi.hssf.usermodel.HSSFCell@b25b9d org.apache.poi.hssf.usermodel.HSSFCell@19ce060 org.apache.poi.hssf.usermodel.HSSFCell@4ecfdd org.apache.poi.hssf.usermodel.HSSFCell@30d82d org.apache.poi.hssf.usermodel.HSSFCell@c09554 org.apache.poi.hssf.usermodel.HSSFCell@18bf072
org.apache.poi.hssf.usermodel.HSSFCell@11b9fb1 org.apache.poi.hssf.usermodel.HSSFCell@56f631 org.apache.poi.hssf.usermodel.HSSFCell@13d28e3 org.apache.poi.hssf.usermodel.HSSFCell@476128 org.apache.poi.hssf.usermodel.HSSFCell@3b8b49 org.apache.poi.hssf.usermodel.HSSFCell@1359c1b org.apache.poi.hssf.usermodel.HSSFCell@9be79a
org.apache.poi.hssf.usermodel.HSSFCell@913fe2 org.apache.poi.hssf.usermodel.HSSFCell@18235ed org.apache.poi.hssf.usermodel.HSSFCell@1a28362 org.apache.poi.hssf.usermodel.HSSFCell@5fcf29 org.apache.poi.hssf.usermodel.HSSFCell@19b1de org.apache.poi.hssf.usermodel.HSSFCell@ec6b00 org.apache.poi.hssf.usermodel.HSSFCell@164dbd5
org.apache.poi.hssf.usermodel.HSSFCell@1f934ad org.apache.poi.hssf.usermodel.HSSFCell@9cb0f4 org.apache.poi.hssf.usermodel.HSSFCell@125844f org.apache.poi.hssf.usermodel.HSSFCell@11978b org.apache.poi.hssf.usermodel.HSSFCell@f42ad0 org.apache.poi.hssf.usermodel.HSSFCell@26dbec org.apache.poi.hssf.usermodel.HSSFCell@1309e87
org.apache.poi.hssf.usermodel.HSSFCell@1f14ceb org.apache.poi.hssf.usermodel.HSSFCell@f7c31d org.apache.poi.hssf.usermodel.HSSFCell@2acc65 org.apache.poi.hssf.usermodel.HSSFCell@1d10a5c org.apache.poi.hssf.usermodel.HSSFCell@ff2413 org.apache.poi.hssf.usermodel.HSSFCell@9980d5 org.apache.poi.hssf.usermodel.HSSFCell@1d95492
org.apache.poi.hssf.usermodel.HSSFCell@f0eed6 org.apache.poi.hssf.usermodel.HSSFCell@13f7281 org.apache.poi.hssf.usermodel.HSSFCell@76ab2f org.apache.poi.hssf.usermodel.HSSFCell@e0cc23 org.apache.poi.hssf.usermodel.HSSFCell@7a1576 org.apache.poi.hssf.usermodel.HSSFCell@1171b26 org.apache.poi.hssf.usermodel.HSSFCell@1f78040
org.apache.poi.hssf.usermodel.HSSFCell@1d05c81 org.apache.poi.hssf.usermodel.HSSFCell@50988 org.apache.poi.hssf.usermodel.HSSFCell@b4e29b org.apache.poi.hssf.usermodel.HSSFCell@18941f7 org.apache.poi.hssf.usermodel.HSSFCell@49d67c org.apache.poi.hssf.usermodel.HSSFCell@1a06e38 org.apache.poi.hssf.usermodel.HSSFCell@1a42792
org.apache.poi.hssf.usermodel.HSSFCell@691f36 org.apache.poi.hssf.usermodel.HSSFCell@2200d5 org.apache.poi.hssf.usermodel.HSSFCell@64ab4d org.apache.poi.hssf.usermodel.HSSFCell@12a55aa org.apache.poi.hssf.usermodel.HSSFCell@5e13ad org.apache.poi.hssf.usermodel.HSSFCell@5dd582 org.apache.poi.hssf.usermodel.HSSFCell@6c585a
org.apache.poi.hssf.usermodel.HSSFCell@18020cc org.apache.poi.hssf.usermodel.HSSFCell@11ca803 org.apache.poi.hssf.usermodel.HSSFCell@5a67c9 org.apache.poi.hssf.usermodel.HSSFCell@153c375 org.apache.poi.hssf.usermodel.HSSFCell@453807 org.apache.poi.hssf.usermodel.HSSFCell@618d26 org.apache.poi.hssf.usermodel.HSSFCell@79e304
org.apache.poi.hssf.usermodel.HSSFCell@e94e92 org.apache.poi.hssf.usermodel.HSSFCell@273686 org.apache.poi.hssf.usermodel.HSSFCell@6caf16 org.apache.poi.hssf.usermodel.HSSFCell@15ad5c6 org.apache.poi.hssf.usermodel.HSSFCell@88e2dd org.apache.poi.hssf.usermodel.HSSFCell@e64686 org.apache.poi.hssf.usermodel.HSSFCell@203c31
org.apache.poi.hssf.usermodel.HSSFCell@12558d6 org.apache.poi.hssf.usermodel.HSSFCell@4fc156 org.apache.poi.hssf.usermodel.HSSFCell@1e2ca7 org.apache.poi.hssf.usermodel.HSSFCell@105bd58 org.apache.poi.hssf.usermodel.HSSFCell@1d1e730 org.apache.poi.hssf.usermodel.HSSFCell@1a116c9 org.apache.poi.hssf.usermodel.HSSFCell@df1832
org.apache.poi.hssf.usermodel.HSSFCell@eb7859 org.apache.poi.hssf.usermodel.HSSFCell@ad8659 org.apache.poi.hssf.usermodel.HSSFCell@4f459c org.apache.poi.hssf.usermodel.HSSFCell@633e5e org.apache.poi.hssf.usermodel.HSSFCell@193c0cf org.apache.poi.hssf.usermodel.HSSFCell@1576e70 org.apache.poi.hssf.usermodel.HSSFCell@11381e7


please advise how can i see cell values instead of object unclear values similar to file running in other project where JDK seems 1.4 where as here JDK seems 1.5
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

First: about the required (short) conversion: are you using a literal 0 or are you using a variable? Also, what version of POI are you using? The HSSFRow#getCell(short) has been deprecated and replaced with HSSFRow#getCell(int). Of course, if you were using the interfaces in the org.apache.poi.ss.* packages then you wouldn't have this problem either, because there is no Row#getCell(short).

About the display problem: You must be calling cell.toString(), or passing it to a method (like System.out.prinln()) which does the same. Apparantly the .toString() method prints a String representation of the Cell, not the Cell's value. You need to get the Cell's value out. If you look at the API, what methods do that?


Steve
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 282
I Am checking for string variable
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 282
I was using
org.apache.poi.***.usermodel package tree


I was checking whether first column of each row of excel is null or some string value or not. If not then I would like to print them.
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 282

As you mentioned i checked API and

getStringCellValue()

printed the value correct for me
sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 282
if (myRow.getCell((short) 0) != null && myRow.getCell((short) 0).toString()!="" && myRow.getCell((short) 0)!=headings.get(0) && myRow.getCell((short) 0)!=headings.get(1) && myRow.getCell((short) 0)!=headings.get(2)&&myRow.getCell((short) 0).getStringCellValue()=="AAA"&& myRow.getCell((short) 0).getStringCellValue()=="BBB"&&myRow.getCell((short) 0).getStringCellValue()=="CCC"){

I was checking like above to print the rows whose first column is non null non empty and has values AAA,BBB,CCC. But it is not showing that result in console.


Next conecern is how to add AAA and BBB and CCC into property file and read it from property file itself in the code.

I created sample.properties file with content
String[] SALE_DATA=AAA,BBB,CCC


I imported it in my java class as
static ResourceBundle genericImporterProp = ResourceBundle.getBundle("sample");


if (myRow.getCell((short) 0) != null && myRow.getCell((short) 0).toString()!="" && myRow.getCell((short) 0)!=headings.get(0) && myRow.getCell((short) 0)!=headings.get(1) && myRow.getCell((short) 0)!=headings.get(2)&&myRow.genericImporterProp.SALE_DATA){

above one also did not work. Please advise




sai rama krishna
Ranch Hand

Joined: May 29, 2009
Posts: 282
myRow.getCell((short) 0).getStringCellValue()=="AAA"

above is not checking for AAA in the first cell for some reason. Please advise
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18887
    
    8

sai rama krishna wrote:myRow.getCell((short) 0).getStringCellValue()=="AAA"

above is not checking for AAA in the first cell for some reason. Please advise


Read our FAQ entry entitled Avoid The Equality Operator (<== click on that link).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cast argument '0' to 'short' error