Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Thinking in Java Book problems(I cant get the authors packages to work)
Thinking in Java Book problems [message #794289] Thu, 09 February 2012 05:25 Go to next message
K Hans is currently offline K HansFriend
Messages: 1
Registered: February 2012
Junior Member
I am very new to java and to the Eclipse IDE.
I have windows Visat and Eclipse Version: 3.7.1
Build id: M20110909-1335

I am learning Java from the book Thinking In Java vol4

In the book the author uses about 30 .java files that are packages, he loads them or I guess imports themm with the statment.
import static net.mindview.util.*


The files are in this direcctory on my hard drive but when I use that import statement the Eclipse IDE underlines net and says:
The import net cannot be resolved


Here is a listing of one of the .java files,,, print.java

//: net/mindview/util/Print.java 
// Print methods that can be used without 
// qualifiers, using Java SE5 static imports: 
package net.mindview.util; 
import java.io.*; 

public class Print { 
// Print with a newline: 
public static void print(Object obj) { 
System.out.println(obj); 
} 
// Print a newline by itself: 
public static void print() { 
System.out.println(); 
} 
// Print with no line break: 
public static void printnb(Object obj) { 
System.out.print(obj); 
} 
// The new Java SE5 printf() (from C): 
public static PrintStream 
printf(String format, Object... args) { 
return System.out.printf(format, args); 
} 
} ///:~ 


If I try to use one of the (classes) inside the print.java in my code the Eclipse IDE
underlines it and says.:
The method Print(String) is undefined for the type HelloWorld

import java.util.*;   
import static net.mindview.util.*;   
  
public class HelloWorld {   
  
       
    public static void main(String[] args) {   
        System.out.println("hello world");   
        print("this does not work");   
    }   
  
}  
 


I have tried to import these files into a src folder and into a package in the source folder, I have also tried to add them to the build path, i have tried adding them to the classpath,importing them into my project and just loading themm into my project.

I have had very little success I was able to get the print.java to work once but the next time tried the same thing it did not work.

What I would really like is to know how I could load these .java files into eclipse so they would be there everytime I start the IDE and would work for the lessons in the book without me having to deal with them all the time.

Failing that I would just like to know a reliable way to get them to work in my java projects.

I have asked this question on a couple of forums already and no one has been able to get it done, I figure if anyone would know someone here should..

Any help is appreciated.
thanks for your time.

K Hans
Re: Thinking in Java Book problems [message #794669 is a reply to message #794289] Thu, 09 February 2012 14:58 Go to previous message
Russell Bateman is currently offline Russell BatemanFriend
Messages: 3798
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 2/8/2012 10:25 PM, K Hans wrote:
> I am very new to java and to the Eclipse IDE.
> I have windows Visat and Eclipse Version: 3.7.1 Build id: M20110909-1335
> I am learning Java from the book Thinking In Java vol4
> In the book the author uses about 30 .java files that are packages, he
> loads them or I guess imports themm with the statment.
> import static net.mindview.util.*
>
> The files are in this direcctory on my hard drive but when I use that
> import statement the Eclipse IDE underlines net and says:
> The import net cannot be resolved
>
> [snip]
>
> Any help is appreciated.
> thanks for your time.
>
> K Hans

Bruce Eckel's is a good book for use as a Java reference, since it's so
complete, but it's pretty heavy as a learning method as compared to,
say, Head First Java which is great fun. I have both, they are
excellent, but really fill different roles on the Java programmer's
bookshelf. This said, ...

In Java, one doesn't import symbols from files, but from compiled packages.

You'll have to incorporate those Java source files into your project.
They'll be compiled along with anything else you might add.

If you wish to read an article about how book source code was turned
into working Eclipse project, see

http://www.javahotchocolate.com/tutorials/corejsf.html

There might be something useful in there. Otherwise, come back to this
forum where we'll be delighted to help you solve Eclipse problems.

For questions purely about Java, I'd suggest javaranch.com, jguru.com
or, if you're in a hurry, stackoverflow.com. Of the first two forums,
the folks are pretty dedicated to Java for the sake of the language
itself in addition to being pretty helpful.

Best of luck!
Previous Topic:Require-Bundle
Next Topic:The string value does not changed
Goto Forum:
  


Current Time: Sun Jun 13 03:46:38 GMT 2021

Powered by FUDForum. Page generated in 0.03295 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top