java新手和通過CMD編譯。 我的課DataAnalyzer.java編譯正常,但包含主程序DataAnalyzerTester.java的類給我一個錯誤。編譯CMD程序時出錯Java程序出錯
DataAnalyzer:
package h1.q3;
import java.util.*;
public class DataAnalyzer
{
public DataAnalyzer(LinkedList<Integer> numList)
{
for (int num : numList)
{
numbers.add(num);
}
}
public int min()
{
smallest = numbers.getFirst();
for(int num : numbers)
{
if(num < smallest) smallest = num;
}
return smallest;
}
public int max()
{
largest = numbers.getFirst();
for(int num : numbers)
{
if(num < largest) largest = num;
}
return largest;
}
public int average()
{
sum = 0;
listSize = 0;
for(int num : numbers)
{
sum += num;
listSize++;
}
return sum/listSize;
}
int largest, smallest, sum, listSize;
LinkedList<Integer> numbers = new LinkedList<Integer>();
}
測試儀:
package h1.q3; import java.util.*; /** * * @author pini */
public class DataAnalyzerTester {
public static void main(String[] args)
{
LinkedList<Integer> numbers = new LinkedList();
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
numbers.add(sc.nextInt());
}
DataAnalyzer da = new DataAnalyzer(numbers);
System.out.println("Minimum: " + da.min());
System.out.println("Maximum: " + da.max());
System.out.println("Average: " + da.average());
}
我得到的錯誤如下:
C:\Users\pini\Documents\NetBeansProjects\Homework1\src\homework1\q3>javac DataAn
alyzer.java
C:\Users\pini\Documents\NetBeansProjects\Homework1\src\homework1\q3>javac DataAn
alyzerTester.java
DataAnalyzerTester.java:24: error: cannot find symbol
DataAnalyzer da = new DataAnalyzer(numbers);
^
symbol: class DataAnalyzer
location: class DataAnalyzerTester
DataAnalyzerTester.java:24: error: cannot find symbol
DataAnalyzer da = new DataAnalyzer(numbers);
^
symbol: class DataAnalyzer
location: class DataAnalyzerTester
Note: DataAnalyzerTester.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
我已經試過一切,仍然無法得到它的編譯測試儀。我很確定我的代碼是好的,但它似乎並沒有識別DataAnalyzer對象。
C:\Users\pini\Documents\NetBeansProjects\Homework1\src\homework1\q3>java DataAna
lyzerTester
Exception in thread "main" java.lang.NoClassDefFoundError: DataAnalyzerTester (w
rong name: homework1/q3/DataAnalyzerTester)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
嘗試javac -classpath「」*。java –