2

I don't understand why I can't even make a new instance, IDE marks inner class name as unassigned

public class WbXLS {

  class XlsCell {
    public String getxlsCell(HSSFSheet sheet, String strCellValue) {

    }
  }
}

Tried without success

WbXLS.XlsCell xlscell = new wbXLS.new XlsCell();

I made the inner class to get return value from method and use it in another class. Am I right doing so?

Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
Rostislav Aleev
  • 351
  • 5
  • 19
  • 1
    this actually compiles?? WbXLS.XlsCell xlscell = new wbXLS.new XlsCell (); try making the nested class static, and -> new WbXLS.XlsCell(); – Stultuske Oct 09 '18 at 13:37
  • @Stultuske it's a problem, I need an inner class, not nested. In the outer class I work with xls workbook '...main void' and the inner class isn't nested because I think it will work so only with full access to outer class. – Rostislav Aleev Oct 09 '18 at 13:40
  • inner classes are (non-static) nested classes – Stultuske Oct 09 '18 at 13:44
  • @Stultuske, static is prohibited. I tried it, syntax error.. – Rostislav Aleev Oct 09 '18 at 13:57
  • Possible duplicate of [Creating instance of inner class outside the outer class in java](https://stackoverflow.com/questions/24506971/creating-instance-of-inner-class-outside-the-outer-class-in-java) – LuCio Oct 09 '18 at 14:02

2 Answers2

2

I think you may be missing brackets. This compiles for me:

WbXLS.XlsCell xlscell = new WbXLS().new XlsCell();
WakamaHeja
  • 31
  • 5
0

Every XlsCell object has a WbXLS.this : a reference to the object container it resides in.

So parenthesis were missing:

WbXLS.XlsCell xlscell = new WbXLS().new XlsCell();

But in effect you probably want:

WbXLS workbook = new WbXLS();
WbXLS.XlsCell xlscell = workbook.new XlsCell();

And do something with one single workbook instance. (For which several cells may be created.)

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138