File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problems with importing from another source code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problems with importing from another source code" Watch "Problems with importing from another source code" New topic
Author

Problems with importing from another source code

Abbey Samuel
Greenhorn

Joined: May 02, 2007
Posts: 15
Actually I have the bruceeckel source code in My Document and also the Java Documentation in the same My Document and each time I try to import from the Java documentation the program gets compiled while the import com.bruceeckel refuses to compile.I think may be this has to do with my classpath or path which I did not set right this is the classpath I set please help me to know how to access this
CLASSPATH:C:\MyJavaLib;C:\MyJavaLib\myutils.jar;C:\MyJavaLib\blackboxclasses.jar;


//: appendixa:MutableInteger.java
// A changeable wrapper class.
import com.bruceeckel.simpletest.*;
import java.util.*;

class IntValue {
private int n;
public IntValue(int x) { n = x; }
public int getValue() { return n; }
public void setValue(int n) { this.n = n; }
public void increment() { n++; }
public String toString() { return Integer.toString(n); }
}

public class MutableInteger {
private static Test monitor = new Test();
public static void main(String[] args) {
List v = new ArrayList();
for(int i = 0; i < 10; i++)
v.add(new IntValue(i));
System.out.println(v);
for(int i = 0; i < v.size(); i++)
((IntValue)v.get(i)).increment();
System.out.println(v);
monitor.expect(new String[] {
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
});
}
} ///:~
Simon Baker
Ranch Hand

Joined: Sep 09, 2004
Posts: 57
Hi Abbey,

It would probably be helpful to include the compilation error you are getting.

However, assuming that the compiled (.class) files you are attempting to import are in one of the two .jar files you mention it would appear there may be a classpath issue.

You might want to try either checking your classpath in the command shell immediately prior to issuing the javac command (if Windows "echo %CLASSPATH%") or using the -classpath option when executing javac (see javac for further info) to ensure that the relevant classes are available to the compiler. My preference is for the latter approach since it avoids cluttering up the user CLASSPATH, which becomes more relevant as you have more programs to compile.

Cheers,
Simon
Abbey Samuel
Greenhorn

Joined: May 02, 2007
Posts: 15
This is the code and the error it throws up



//: appendixa:MutableInteger.java
// A changeable wrapper class.
import com.bruceeckel.simpletest.*;
import java.util.*;

class IntValue {
private int n;
public IntValue(int x) { n = x; }
public int getValue() { return n; }
public void setValue(int n) { this.n = n; }
public void increment() { n++; }
public String toString() { return Integer.toString(n); }
}

public class MutableInteger {
private static Test monitor = new Test();
public static void main(String[] args) {
List v = new ArrayList();
for(int i = 0; i < 10; i++)
v.add(new IntValue(i));
System.out.println(v);
for(int i = 0; i < v.size(); i++)
((IntValue)v.get(i)).increment();
System.out.println(v);
monitor.expect(new String[] {
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]",
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
});
}
} ///:~

Actually I have the bruceeckel source code in My Document and also the Java Documentation in the same My Document and each time I try to import from the Java documentation the program gets compiled while the import com.bruceeckel refuses to compile.I think may be this has to do with my classpath or path which I did not set right this is the classpath I set please help me to know how to access this
CLASSPATH:C:\MyJavaLib;C:\MyJavaLib\myutils.jar;C:\MyJavaLib\blackboxclasses.jar;
C:\Documents and Settings\User\My Documents\IntValue.java:15: class MutableInteger is public, should be declared in a file named MutableInteger.java
public class MutableInteger {
^
C:\Documents and Settings\User\My Documents\IntValue.java:3: package com.bruceeckel.simpletest does not exist
import com.bruceeckel.simpletest.*;
^
C:\Documents and Settings\User\My Documents\IntValue.java:16: cannot find symbol
symbol : class Test
location: class MutableInteger
private static Test monitor = new Test();
^
C:\Documents and Settings\User\My Documents\IntValue.java:16: cannot find symbol
symbol : class Test
location: class MutableInteger
private static Test monitor = new Test();
^
Note: C:\Documents and Settings\User\My Documents\IntValue.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
4 errors

Tool completed with exit code 1
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

First, if you're setting a system CLASSPATH, you should also include the current directory, which is denoted by a "dot" (period). For example...

Second, note that the structure of your directories is important. You need to have a directory called "com" that contains a subdirectory called "bruceeckel" that contains a subdirectory called "simpletest". Your classpath should include the path to where "com" is. (For example, a good place for the "com" directory might be under C:\MyJavaLib, which is already in your classpath.)

Since you're using Eckel's Thinking in Java, you should refer to his chapter "Hiding the Implementation" for details about using packages, imports, and classpath.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Vyas
Greenhorn

Joined: May 21, 2007
Posts: 17
You need to have the library files in proper directory and structure
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

"Vyas", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abbey Samuel
Greenhorn

Joined: May 02, 2007
Posts: 15
Vyas try and comply it cost you nothing to update this information
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems with importing from another source code