Avatar of sadaf_syed
sadaf_syed

asked on 

get 2 java error please help

i get these two java errors:
s
D:\java_src\RMARepair\src\RMARepairs\RMARepairs.java:649: createRow(short) in org.apache.poi.hssf.usermodel.HSSFSheet cannot be applied to (int)
    HSSFRow row = sheet.createRow(0);
D:\java_src\RMARepair\src\RMARepairs\RMARepairs.java:661: createRow(short) in org.apache.poi.hssf.usermodel.HSSFSheet cannot be applied to (int)
        row = sheet.createRow(rowCnt);
private HSSFWorkbook createSpreadsheet(StringBuffer a_sb){
    char[] c = a_sb.toString().toCharArray();
    
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("RMA Repairs");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell((short)0);
    
    int rowCnt = 0;
    short colCnt = 0;
    for (int i = 0; i < c.length; i++){
      if (c[i] == '\n'){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        rowCnt++;
        row = sheet.createRow(rowCnt);
        colCnt = 0;
        cell = row.createCell(colCnt);
      }
      else if (c[i] == (char)9){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        colCnt++;
        cell = row.createCell(colCnt);
      }
      else{
        cell.setCellValue(cell.getStringCellValue() + c[i]);
      }
    }
    
   
    return workbook;

Open in new window

Java

Avatar of undefined
Last Comment
sciuriware
ASKER CERTIFIED SOLUTION
Avatar of sciuriware
sciuriware

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Per Java syntax rules, methods that take a primitive numeric argument will automatically cast an argument value that is a smaller primitive type because the destination type can hold larger values than the source but an explict cast is required when the destination type (short in this case) is smaller than the source (int) because the value could possibly be truncated at runtime. The compiler requires that you explicitly state your intention by supplying the cast.
Please do not accept this answer as the solution as sciuriware's answer is correct.
Regards
Avatar of sciuriware
sciuriware

Thanks, where have you been all that time?

;JOOP!
You might want to use the latest version of POI 3.2
http://www.apache.org/dyn/closer.cgi/poi/release/

public HSSFCell createCell(short columnIndex)
has been deprecated.
http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFRow.html#createCell(short) 

If you are using POI 3.2 the following will work for u.

Change 1
    HSSFCell cell = row.createCell((short)0);
to
    HSSFCell cell = row.createCell(0);

Change 2
    short colCnt = 0;
to
    int colCnt = 0;

private HSSFWorkbook createSpreadsheet(StringBuffer a_sb){
    char[] c = a_sb.toString().toCharArray();
    
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("RMA Repairs");
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell = row.createCell(0);
    
    int rowCnt = 0;
    int colCnt = 0;
    for (int i = 0; i < c.length; i++){
      if (c[i] == '\n'){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        rowCnt++;
        row = sheet.createRow(rowCnt);
        colCnt = 0;
        cell = row.createCell(colCnt);
      }
      else if (c[i] == (char)9){
        if (isNumeric(cell.getStringCellValue())){
          cell.setCellValue(Double.valueOf(cell.getStringCellValue()).doubleValue());
        }
        
        colCnt++;
        cell = row.createCell(colCnt);
      }
      else{
        cell.setCellValue(cell.getStringCellValue() + c[i]);
      }
    }
    
   
    return workbook;
}

Open in new window

Avatar of sciuriware
sciuriware

:)
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo