0

So I'm still a beginner at programming and Java. There is an upcoming project in a company where I currently am as a High School Intern. Part of that project is reading excel files and storing the data in variables to be used later.

To learn more about file reading and writing, I tried codes that I found on the internet to implement once and then go over them to understand what is going on in there. The problem is, most codes online show multiple Syntax errors and just straight up don't work. There isn't any real step by step guide that explains what exactly is required for reading Excel files and how to write a code for that.

Since i'm too dumb to figure out the formatting on this site, here is an image of part of the code that gives problem.

Apparently there seems to be no Syntax issue other than the unqualified enum. I'm using NetBeans IDE and it only highlights these three:

1) Cell.CELL_TYPE_NUMERIC: error: an enum switch case label must be the unqualified name of an enumeration constant case Cell.CELL_TYPE_NUMERIC

2) Cell.CELL_TYPE_STRING:error: an enum switch case label must be the unqualified name of an enumeration constant case Cell.CELL_TYPE_STRING

3) Cell.CELL_TYPE_BOOLEAN:error: an enum switch case label must be the unqualified name of an enumeration constant case Cell.CELL_TYPE_BOOLEAN

Gopal Bhuva
  • 654
  • 2
  • 13
  • 20
A.Wasey
  • 23
  • 3
  • Dont make pictures of Code... – Raw Jul 30 '19 at 06:34
  • 2
    *Unqualified* means, you don't have to explicitly write the type before the `enum` values or class constants. First thing I've seen in your image (!) of code is `switch (Cell.getCellType())`, which should be `switch (cell.getCellType())` and then just write the `cases` without explicit qualification `Cell.`, just `case CELL_TYPE_SOMETHING: doIt(); break;`... – deHaar Jul 30 '19 at 06:40
  • Please read https://stackoverflow.com/editing-help to see how to format code. You can also use triple-backticks rather than indentation now, e.g. https://gist.github.com/jskeet/70b7e6884f9485c2f36f1d5bbd904df0 – Jon Skeet Jul 30 '19 at 07:43
  • On entering code: an indented block (4 spaces) with empty lines above and below make code. – Joop Eggen Jul 30 '19 at 07:55
  • @JonSkeet, I tried formatting both ways, it still wouldn't accept. – A.Wasey Jul 30 '19 at 10:47
  • What do you mean by "it still wouldn't accept"? What *exactly* happened? It's important to learn how to format code in order to be successful on Stack Overflow. – Jon Skeet Jul 30 '19 at 10:52
  • @JonSkeet, I figured out the indents, there was incorrect spacing at the beginning. I tried it again with a code and its accepting it now. Thanks – A.Wasey Aug 02 '19 at 06:44

1 Answers1

1

case in a switch case doesn't accept the Enum type (as it's automatically written by the compiler) :

switch(cell.getType()) {
  case CELL_TYPE_NUMERIC:
  // will compile as case Cell.CELL_TYPE_NUMERIC
    //doSomething()
    break;
  default:
    //doSomething()
}

Follow this post as a tutorial

IQbrod
  • 2,060
  • 1
  • 6
  • 28