• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Error:java: incompatible types: org.apache.poi.ss.usermodel.CellType cannot be converted to int  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a code i used for COMPARE EXCEL. However I get the below errors :

Error:(106, 42) java: incompatible types: org.apache.poi.ss.usermodel.CellType cannot be converted to int
Error:(107, 42) java: incompatible types: org.apache.poi.ss.usermodel.CellType cannot be converted to int
Error:(112, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(117, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(117, 25) java: duplicate case label
Error:(123, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(123, 25) java: duplicate case label
Error:(129, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(129, 25) java: duplicate case label
Warning:(130, 64) java: CELL_TYPE_BLANK in org.apache.poi.ss.usermodel.Cell has been deprecated
Error:(130, 53) java: incomparable types: org.apache.poi.ss.usermodel.CellType and int
Error:(134, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(134, 25) java: duplicate case label
Error:(140, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(140, 25) java: duplicate case label

 
Master Rancher
Posts: 4042
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CellType is not an int, as the error says.
For the switch statement, in the case bits you don't use the enum class name, just the value.
 
Sandy Shree
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many thanks Dave : I made the following change

 // Compare Two Cells
       public static boolean compareTwoCells(XSSFCell cell1, XSSFCell cell2) {
           if((cell1 == null) && (cell2 == null)) {
               return true;
           } else if((cell1 == null) || (cell2 == null)) {
               return false;
           }

           boolean equalCells = false;
           CellType type1 = cell1.getCellType();
           CellType type2 = cell2.getCellType();
           if (type1 == type2) {
               if (cell1.getCellStyle().equals(cell2.getCellStyle())) {
                   // Compare cells based on its type
                   switch (cell1.getCellType()) {
                       case HSSFCell.CELL_TYPE_FORMULA:
                           if (cell1.getCellFormula().equals(cell2.getCellFormula())) {
                               equalCells = true;
                           }
                           break;
                       case HSSFCell.CELL_TYPE_NUMERIC:
                           if (cell1.getNumericCellValue() == cell2
                                   .getNumericCellValue()) {
                               equalCells = true;
                           }
                           break;
                       case HSSFCell.CELL_TYPE_STRING:
                           if (cell1.getStringCellValue().equals(cell2
                                   .getStringCellValue())) {
                               equalCells = true;
                           }
                           break;
                       case HSSFCell.CELL_TYPE_BLANK:
                           if (cell2.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
                               equalCells = true;
                           }
                           break;
                       case HSSFCell.CELL_TYPE_BOOLEAN:
                           if (cell1.getBooleanCellValue() == cell2
                                   .getBooleanCellValue()) {
                               equalCells = true;
                           }
                           break;
                       case HSSFCell.CELL_TYPE_ERROR:
                           if (cell1.getErrorCellValue() == cell2.getErrorCellValue()) {
                               equalCells = true;
                           }
                           break;
                       default:
                           if (cell1.getStringCellValue().equals(
                                   cell2.getStringCellValue())) {
                               equalCells = true;
                           }
                           break;
                   }


Could you kindly elaborate what I should change in Switch statement when you say not to use the Enum but just the value please.


I see the below error now:

Error:(113, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(118, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(118, 25) java: duplicate case label
Error:(124, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(124, 25) java: duplicate case label
Error:(130, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(130, 25) java: duplicate case label
Warning:(131, 64) java: CELL_TYPE_BLANK in org.apache.poi.ss.usermodel.Cell has been deprecated
Error:(131, 53) java: incomparable types: org.apache.poi.ss.usermodel.CellType and int
Error:(135, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(135, 25) java: duplicate case label
Error:(141, 38) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(141, 25) java: duplicate case label
 
Dave Tolls
Master Rancher
Posts: 4042
47
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of:

use:

 
Sandy Shree
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,
Thanks yet again for helping. I am a beginner in Java and I have used this code from internet and hence my question may sound very basic to you. I hope you can forgive my low knowledge in the matter.
I now removed the HSSFCell from each case statement.

I now have the below code:

       public static boolean compareTwoCells(XSSFCell cell1, XSSFCell cell2) {
           if((cell1 == null) && (cell2 == null)) {
               return true;
           } else if((cell1 == null) || (cell2 == null)) {
               return false;
           }

           boolean equalCells = false;
           CellType type1 = cell1.getCellType();
           CellType type2 = cell2.getCellType();
           if (type1 == type2) {
               if (cell1.getCellStyle().equals(cell2.getCellStyle())) {
                   // Compare cells based on its type
                   switch (cell1.getCellType()) {
                       case CELL_TYPE_FORMULA:
                           if (cell1.getCellFormula().equals(cell2.getCellFormula())) {
                               equalCells = true;
                           }
                           break;
                       case CELL_TYPE_NUMERIC:
                           if (cell1.getNumericCellValue() == cell2
                                   .getNumericCellValue()) {
                               equalCells = true;
                           }
                           break;
                       case CELL_TYPE_STRING:
                           if (cell1.getStringCellValue().equals(cell2
                                   .getStringCellValue())) {
                               equalCells = true;
                           }
                           break;
                       case CELL_TYPE_BLANK:
                           if (cell2.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
                               equalCells = true;
                           }
                           break;
                       case CELL_TYPE_BOOLEAN:
                           if (cell1.getBooleanCellValue() == cell2
                                   .getBooleanCellValue()) {
                               equalCells = true;
                           }
                           break;
                       case CELL_TYPE_ERROR:
                           if (cell1.getErrorCellValue() == cell2.getErrorCellValue()) {
                               equalCells = true;
                           }
                           break;
                       default:
                           if (cell1.getStringCellValue().equals(
                                   cell2.getStringCellValue())) {
                               equalCells = true;
                           }
                           break;
                   }
               } else {
                   return false;
               }
           } else {
               return false;
           }
           return equalCells;
       }
   }

Errors now are :

Error:(115, 30) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(120, 30) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(126, 30) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(132, 30) java: an enum switch case label must be the unqualified name of an enumeration constant
Warning:(133, 64) java: CELL_TYPE_BLANK in org.apache.poi.ss.usermodel.Cell has been deprecated
Error:(133, 53) java: incomparable types: org.apache.poi.ss.usermodel.CellType and int
Error:(137, 30) java: an enum switch case label must be the unqualified name of an enumeration constant
Error:(143, 30) java: an enum switch case label must be the unqualified name of an enumeration constant

Thanks for your patience in this matter. really helps my learning.
 
Dave Tolls
Master Rancher
Posts: 4042
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hang on.
getCellType returns a CellType enum, not an HSSFCell.

You need to be checking against the enum values of CellType, not any old value.
 
Sandy Shree
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to say

 boolean equalCells = false;
           CellType type1 = cell1.getCellType();
           CellType type2 = cell2.getCellType();
           if (type1 == type2) {

I need to change the getCellType function to something else ?
 
Marshal
Posts: 64167
215
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you trying to do? I think you need to decide that before you write any code. You have several methods which claim to determine whether two cells are or are not the same, but I don't think they either show equality nor any comparison. They test for nullity, in which case don't writeNot only may that fail to compile, but a look at the old Sun Style Guide tells you you should writeBut I suspect that isn't a correct implementation of what you actually want.
 
Dave Tolls
Master Rancher
Posts: 4042
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sandy Shree wrote:Do you mean to say



What I'm trying to say is that all these errors are to do with the switch statement.

When you do a switch on a value, the case statements need to be for values that are allowed for the type used in a switch.

So a switch on an int, all the values need to be a valid int.

A switch on an enum (as you are doing with the CellType), all the case statements need to be for values from that enum.

None of the values you are using are part of the CellType enum.
(That's a link to the Apache POI JavaDoc for CellType).
 
Campbell Ritchie
Marshal
Posts: 64167
215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why do you need the switch in the first place?
 
Dave Tolls
Master Rancher
Posts: 4042
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because they seem to be comparing the values in the cells.
And the way POI works is there is a different method depending on what the CellType is.

Cells do not override equals, largely because one persons "equal" is not anothers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!