Results 1 to 11 of 11
  1. #1
    EasternDude is offline Member
    Join Date
    Oct 2014
    Posts
    5
    Rep Power
    0

    Default beginer with ECLIPSE. probelms importing packages.

    Hello. im a 1st year student and at uni we are using this sheffield package when writing programs. Usually we write code with jEdit, Notepad++ or other smple editor and compile it using cmd.

    Normally i drop 'sheffield' folder with classes where my source is, and it works just fine. compiles and runs through cmd.

    little test-example:
    Java Code:
    import sheffield.*;
    
    public class test1{
    public static void main(String[] args){
    
    	EasyWriter screen = new EasyWriter();
    	
    	int arrayint[] = {10,3,8,7,9,0,11,56,5,18,13,2,19};
    	int arrayint2[] = new int[10];
    	
    		for (int i = 0; i< arrayint.length;i++){
    			screen.print(arrayint[i]+"| ");
    		}
    		
    	screen.println();
    	screen.println("length of arrayint: "+arrayint.length);
    	screen.println("length of arrayint2: "+arrayint2.length);
    	
    		System.arraycopy(arrayint,2,arrayint2,1,9);
    		
    		for (int i = 0; i< arrayint2.length;i++){
    			screen.print(arrayint2[i]+"| ");
    		}
    		screen.println();
    
    }
    };
    I want to go more advanced and start using this Eclipse-IDE. However, i tried some testing and noticed that importing packages dosen't work the same way. Eclipse is giving me errors when trying exactly same code as before:

    beginer with ECLIPSE. probelms importing packages.-errors1.png

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

    Default Re: beginer with ECLIPSE. probelms importing packages.

    Have you tried adding the jar file(s) to your build path? Right click your project name and go to build path. You can also create you own libraries and add those to your build path too.

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

  3. #3
    EasternDude is offline Member
    Join Date
    Oct 2014
    Posts
    5
    Rep Power
    0

    Default Re: beginer with ECLIPSE. probelms importing packages.

    what .jar files? the package im trying to use dosen't contain any .jar files. its just a few .java and .class files.

    oh and yes i tried to add them somewhere in project settings. Didn't work or i'm not getting how to do it correctly :(

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

    Default Re: beginer with ECLIPSE. probelms importing packages.

    Ok, bad assumption on my part. So here is the problem. The zip file contains classes which declare a package called sheffield. However, those classes are not in a sheffield folder within the zip file. So the easiest solution is as follows:

    1. Create a directory/folder called sheffieldLibrary
    2. within that create another directory/folder called sheffield.
    3. Into that last folder, extract the zip file.
    4. Go to Eclipse and right click on the project name then on build path.
    5. Then click on "Configure Build Path..."
    6. Then click on "Add External Class Folder..."
    7. Then add the sheffieldLibrary folder from above.

    That should do it. Then when you type in EasyRead a; you can then hit CTRL-SHIFT-O to import the class.

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

  5. #5
    EasternDude is offline Member
    Join Date
    Oct 2014
    Posts
    5
    Rep Power
    0

    Default Re: beginer with ECLIPSE. probelms importing packages.

    Thanks for your help. Although, something really strange happenes when i try this. When i run the code it DOES print stuff corretly to console but STILL GIVES ERROS anyway.. :/ weird stuff.
    beginer with ECLIPSE. probelms importing packages.-ugly_ugly_errors.png

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

    Default Re: beginer with ECLIPSE. probelms importing packages.

    What do your imports look like? In my example, the sheffieldLibrary is not part of the package name. It is the name of the folder that contains the package. So the package declaration should be:

    import sheffield.*;

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

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: beginer with ECLIPSE. probelms importing packages.

    It's because the zip has been extracted into the src directory of the project. so Eclipse is trying to build it as part of the project.
    This fails because the package declaration at the top of the "sheffield" source files is "package sheffield;", but the folder they are in is "sheffieldLibrary/sheffield" so the compiler flags an error.

    Since these are source files they need to be compiled.
    If you want to do this properly I would suggest creating a new project in Eclipse for this, and get Eclipse to create a simple jar file for you.
    You can then simply copy that jar file into any project you need it in (stick it in a lib directory in the project and add the jar to the build path).
    You probably haven't done anything with jar files yet, so consider this a learning exercise.

    The other option is to unzip them directly into the src directory, and check the top level directory is "sheffield".
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: beginer with ECLIPSE. probelms importing packages.

    Quote Originally Posted by Tolls View Post
    This fails because the package declaration at the top of the "sheffield" source files is "package sheffield;", but the folder they are in is "sheffieldLibrary/sheffield"
    Assuming I understand what you are saying, I don't believe that is the problem. As long as the "location" of the package directory is specified as sheffieldLibrary(similar to specifying the location is E:\ or some other top level directory). And I told the OP to do that in steps 6 & 7 above. Also, the zip file also includes class files. I tried all this out on my machine and it worked just fine with no errors or complaints.

    I think the OP either messed up steps 6 and 7 or specified the wrong package name within the source file(s).

    Regards,
    Jim
    Last edited by jim829; 01-06-2015 at 02:33 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: beginer with ECLIPSE. probelms importing packages.

    Didn't realise it had the class files in it.

    I'd still jar it up.
    In fact couldn't you simply change .zip to .jar?

    But yes, if there's class files then they've unzipped it into the wrong place (as per your instructions).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: beginer with ECLIPSE. probelms importing packages.

    Quote Originally Posted by Tolls View Post
    I'd still jar it up.
    I agree. But considering that Eclipse Jar tools are rather lousy (imho) I tried to make it a little simpler.

    In fact couldn't you simply change .zip to .jar?
    I never thought of that! I would have thought it would need a MANIFEST file. I am not well versed on Jar file requirements.

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

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: beginer with ECLIPSE. probelms importing packages.

    It only occurred to me as I was writing that post.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Importing Packages
    By Tartaglia in forum New To Java
    Replies: 4
    Last Post: 07-12-2012, 11:15 PM
  2. Importing Packages
    By shadowfax57 in forum New To Java
    Replies: 3
    Last Post: 12-28-2010, 07:48 PM
  3. importing packages
    By mustachMan in forum New To Java
    Replies: 3
    Last Post: 01-20-2010, 05:07 AM
  4. help with importing packages
    By orrymr in forum New To Java
    Replies: 1
    Last Post: 08-07-2009, 08:18 PM
  5. Replies: 3
    Last Post: 02-12-2008, 11:03 AM

Posting Permissions

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