Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

illegal forward reference in java

Tags:

java

 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?

like image 733
Karthik.m Avatar asked Nov 17 '09 05:11

Karthik.m


2 Answers

"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(...); 
like image 60
erickson Avatar answered Oct 17 '22 07:10

erickson


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(...) 
like image 32
sanastasiadis Avatar answered Oct 17 '22 08:10

sanastasiadis