L
lonelyplanet999
Hi,
I'm learning java programming and I use java SDK 1.4 for writing
programs.
I met one problem about importing self developed class illustrated by
below examples:
File: c:\javapgm\Caltor.java
File content:
package Caltor;
class Calculator {
private String[] functions = {"+", "-", "*", "/", "="};
String getFunctions() {
String s = functions[0];
for (int i=1; i<functions.length; i++)
s += ", " + functions;
return s;
}
}
File: c:\javapgm\Tester.java
File content:
import Caltor.*;
class Tester {
public static void main (String[] args) {
Calculator c = new Calculator();
System.out.println(c.getFunctions());
}
}
Compiling Caltor.java returned no error.
Compiling Tester.java returned below error.
Tester.java:4: package Caltor does not exist
import Caltor.*;
^
Tester.java:8: cannot access Calculator
bad class file: .\Calculator.class
class file contains wrong class: Caltor.Calculator
Please remove or make sure it appears in the correct subdirectory of
the classpath.
Calculator c = new Calculator();
^
2 errors
I tried create a subdirectory named Caltor under c:\javapgm\ but still
couldn't make compilation of Tester.java succeed.
Could anyone help me how to fix this problem ? I found no clue from
books teaching java programming nor could I find answer from sun's FAQ
list for java programming.
Tks!
I'm learning java programming and I use java SDK 1.4 for writing
programs.
I met one problem about importing self developed class illustrated by
below examples:
File: c:\javapgm\Caltor.java
File content:
package Caltor;
class Calculator {
private String[] functions = {"+", "-", "*", "/", "="};
String getFunctions() {
String s = functions[0];
for (int i=1; i<functions.length; i++)
s += ", " + functions;
return s;
}
}
File: c:\javapgm\Tester.java
File content:
import Caltor.*;
class Tester {
public static void main (String[] args) {
Calculator c = new Calculator();
System.out.println(c.getFunctions());
}
}
Compiling Caltor.java returned no error.
Compiling Tester.java returned below error.
Tester.java:4: package Caltor does not exist
import Caltor.*;
^
Tester.java:8: cannot access Calculator
bad class file: .\Calculator.class
class file contains wrong class: Caltor.Calculator
Please remove or make sure it appears in the correct subdirectory of
the classpath.
Calculator c = new Calculator();
^
2 errors
I tried create a subdirectory named Caltor under c:\javapgm\ but still
couldn't make compilation of Tester.java succeed.
Could anyone help me how to fix this problem ? I found no clue from
books teaching java programming nor could I find answer from sun's FAQ
list for java programming.
Tks!