Results 1 to 6 of 6
  1. #1
    litlmike is offline Member
    Join Date
    May 2016
    Posts
    6
    Rep Power
    0

    Default How to #include in JAVA / Eclipse

    I need some help figuring out how to get started in JAVA and Eclipse. I am trying to use the Apache POI to work with Excel, but I think I am having some issues with dependencies. I am used to using #include in other languages, and not sure how to do this in JAVA. Please speak to me as you would a small child. I have spent a lot of time Googling a solution, but I am obviously missing something here. Here are the steps I've taken:

    1) I downloaded this poi-bin-3.15-beta1-20160409.tar.gz to workspace
    2) Extracted it to root\poi-3.15-beta1
    3) Opened Eclipse and "Create a Java Project"
    4) Settings:
    Project name: ApachePOIStuff
    Default settings
    Libraries: Add External JAR:
    poi-3.15-beta1.jar
    poi-ooxml-3.15-beta1.jar
    poi-ooxml-schemas-3.15-beta1.jar
    poi-scratchpad-3.15-beta1.jar

    Order and Export
    Check the boxes for the imported .jar
    5) Click Finish
    6) New Class
    Name:ThisIsATest
    Checked:
    -public static void
    -constructors
    -inherited
    7) Click Finish
    8) Here is my code in class:
    Java Code:
    public class Thisisatest {
    
    	public Thisisatest() {
    		// TODO Auto-generated constructor stub
    	}
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Workbook wb = new HSSFWorkbook();
    	    FileOutputStream fileOut = new FileOutputStream("workbook.xls");
    	    wb.write(fileOut);
    	    fileOut.close();
    	}
    
    }
    9) Errors:
    "Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    Workbook cannot be resolved to a type
    XSSFWorkbook cannot be resolved to a type

    at DoSomeStuff.main(DoSomeStuff.java:17)"

    HALP! Again, speak to me as you would a small child.

  2. #2
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: How to #include in JAVA / Eclipse

    You may be seeking for the import statement, who "includes" classes in other packages to be accessed from your project classes.

  3. #3
    litlmike is offline Member
    Join Date
    May 2016
    Posts
    6
    Rep Power
    0

    Default Re: How to #include in JAVA / Eclipse

    Thank you!

  4. #4
    Join Date
    May 2016
    Location
    Brazil
    Posts
    16
    Rep Power
    0

    Default Re: How to #include in JAVA / Eclipse

    Okay!

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: How to #include in JAVA / Eclipse

    You can't successfully import a class if the compiler can't find it. So click on the project name in Eclipse and configure the build path.
    There should be a libraries tab where you can add the appropriate jar files.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How to #include in JAVA / Eclipse

    The include statement and the import statement are quite different.
    The include statement causes source lines from another file to be "included" in the source file being compiled.
    The import statement gives the compiler a path that can be used to find class definitions allowing the programmer to use just the class name without the package name. With "import java.io.*;" you can code just the class name: BufferedReader instead of java.io.BufferedReader.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. include jre in java project
    By samara in forum Java JDK
    Replies: 1
    Last Post: 12-17-2013, 01:16 PM
  2. PHP include on Java?
    By KingdomX in forum New To Java
    Replies: 4
    Last Post: 12-24-2011, 11:55 PM
  3. Replies: 0
    Last Post: 03-02-2010, 08:28 AM
  4. include-prelude/include-coda
    By devin in forum Java Servlet
    Replies: 0
    Last Post: 02-11-2009, 07:33 PM
  5. jsp:include and include file
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-14-2007, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •