可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
import java.io.*; import jxl.*; class Xlparsing { Workbook wb =wb.getWorkbook(new File( "C:\\Documents and Settings\\kmoorthi\\Desktop\\ak\\new.xls")); // Illegal forward reference What it means Sheet st = wb.getSheet(0); Cell cell1 = st.getCell(0,0); String a1 = cell1.getContents(); public static void main(String s[]) { System.out.println(new Xlparsing().a1); } }
Hi When I tried to extract data from excel sheet illegal forward reference error comes in the file object creation.
How to resolve this?
回答1:
"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(...);
回答2:
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
.
回答3:
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(...)
回答4:
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".