• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Problems with importing from another source code

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]"
});
}
} ///:~
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to have the library files in proper directory and structure
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Abbey Samuel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vyas try and comply it cost you nothing to update this information
 
Get off me! Here, read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic