illegal forward reference in java

后端 未结 4 1316
Happy的楠姐
Happy的楠姐 2020-12-09 15:50
 import java.io.*;
 import jxl.*;
 class Xlparsing
 {
   Workbook wb =wb.getWorkbook(new File(
    \"C:\\\\Documents and Settings\\\\kmoorthi\\\\Desktop\\\\ak\\\\new         


        
相关标签:
4条回答
  • 2020-12-09 15:58

    although getWorkbook is static, so accordingly, this code should have worked. But here, using the reference before its declaration or in the same statement as declaration is causing error "Forward referencing i.e. using reference before declaration".

    0 讨论(0)
  • 2020-12-09 15:59

    I guess that the intention was to call 'statically' the getWorkbook() method, as you should. So, you should change your wb member initialization as:

    Workbook wb = Workbook.getWorkbook(...)
    
    0 讨论(0)
  • 2020-12-09 16:01

    "Illegal forward reference" means that you are trying to use a variable before it is defined.

    In this case, you are trying to invoke a method on wb in the declaration of wb.

    Workbook wb = wb.getWorkbook(...);
    
    0 讨论(0)
  • 2020-12-09 16:20

    Forward Illegal Reference is a term which comes into picture when an uninitialized non global variable value is assigned to a global variable.

    In your case Workbook wb = wb.getWorkbook(new File("----")); - wb is uninitialized before calling the getWorkbook() method. For avoiding the FIR you should initialize wb.

    0 讨论(0)
提交回复
热议问题