我收到编译错误,我不明白为什么。
控制台输出:
[javac] Compiling 43 source files to C:\Users\Janus\Desktop\gdi1_projekt\gwittest\build\classes
[javac] C:\Users\Janus\Desktop\gdi1_projekt\gwittest\src\testpackage\shared\ship\exceptions\InvalidLevelException.java:43: cannot find symbol
[javac] symbol : method getBoardString(java.lang.Character[][])
[javac] location: class testpackage.shared.ship.Map2DHelper<java.lang.Character>
[javac] System.err.println(helper.getBoardString(char3d[0]));
[javac] ^
[javac] C:\Users\Janus\Desktop\gdi1_projekt\gwittest\src\testpackage\shared\ship\exceptions\InvalidLevelException.java:45: cannot find symbol
[javac] symbol : method getBoardString(java.lang.Character[][])
[javac] location: class testpackage.shared.ship.Map2DHelper<java.lang.Character>
[javac] System.err.println(helper.getBoardString(char3d[1]));
[javac] ^
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
BUILD FAILED
InvalidLevelException:
package testpackage.shared.ship.exceptions;
import java.util.List;
import testpackage.shared.ship.Map2DHelper;
public class InvalidLevelException extends RuntimeException {
private String message;
private List<List<Character>> list2d;
private Character[][][] char3d;
private BoardType type;
private enum BoardType {
Char3D, List2D
}
public InvalidLevelException(String string) {
this.message = string;
}
public void setBoards(Character[][][] char3d) {
this.type = BoardType.Char3D;
this.char3d = char3d;
}
public InvalidLevelException(String string, Character[][][] char3d) {
this(string);
this.type = BoardType.Char3D;
this.char3d = char3d;
}
public InvalidLevelException(String string, List<List<Character>> list2d) {
this(string);
this.type = BoardType.List2D;
this.list2d = list2d;
}
public String getMessage() {
return message + (type == null ? "" : ". Invalid board available. Call InvalidLevelException.printBoard()");
}
public void printBoard() {
if (type == null) {
System.err.println("No invalid board available for debugging.");
} else if (type == BoardType.Char3D) {
Map2DHelper<Character> helper = new Map2DHelper<Character>();
System.err.println(helper.getBoardString(char3d[0]));
System.err.println();
System.err.println(helper.getBoardString(char3d[1]));
} else if (type == BoardType.List2D) {
Map2DHelper<Character> helper = new Map2DHelper<Character>();
System.err.println(helper.getBoardString(list2d));
} else {
System.err.println("Don't know how to print invalid board.");
}
}
private static final long serialVersionUID = 1L;
}
Map2DHelper片段:
public class Map2DHelper<T> {
public String getBoardString(List<List<T>> a) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a.get(i).size(); j++) {
//sb.append(Integer.toString(i) + "," + Integer.toString(j));
sb.append(Util.format("%d ", a.get(i).get(j)));
}
sb.append("\n");
}
sb.append("\n");
return sb.toString();
}
String getBoardString(T[][] a) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
//System.err.println(a[i][j]);
sb.append(String.format("%d ", a[i][j]));
}
sb.append("\n");
}
sb.append("\n");
//System.err.println(sb.toString());
return sb.toString();
}
}
构建脚本(我使用清除的默认目标):
<project name="HelloWorld" basedir="." default="main">
<property name="gwt.user" value="jars/gwt-2.3.0/gwt-user.jar" />
<property name="translator" value="jars/translator.jar"/>
<property name="acm" value="jars/acm.jar"/>
<path id="project.class.path">
<pathelement path="jars/mp3spi1.9.5.jar" />
<pathelement path="jars/tritonus_share.jar" />
<pathelement path="jars/commons-io-2.0.1.jar" />
<pathelement path="jars/jl1.0.1.jar" />
<pathelement path="jars/junit-4.9b3.jar"/>
<pathelement path="${gwt.user}" />
<pathelement path="${acm}" />
<pathelement path="${translator}" />
</path>
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="testpackage.interfaces.GUISchiffe" />
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="on" debuglevel="lines,vars,source">
<exclude name="testpackage/highscore/*.java" />
<classpath refid="project.class.path" />
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<manifestclasspath property="jar-class-path" jarfile="${jar.dir}/${ant.project.name}.jar">
<classpath refid="project.class.path"/>
</manifestclasspath>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${jar-class-path}" />
</manifest>
<fileset dir="war/template"/>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" classpathref="project.class.path" fork="true" />
</target>
<target name="alternaterun" depends="jar">
<java classname="testpackage.interfaces.SoundStreamPlayer">
<classpath>
<pathelement location="${jar.dir}/${ant.project.name}.jar" />
<path refid="project.class.path" />
</classpath>
</java>
</target>
<target name="linux-run" depends="jar">
<exec executable="/usr/bin/aoss">
<arg value="/usr/lib/jvm/java-6-sun/bin/java" />
<arg value="-jar" />
<arg value="build/jar/HelloWorld.jar" />
</exec>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
</project>
答案 0 :(得分:1)
可能只是因为getBoardString(T [] [] ...不公开吗?因为你在第一个lusting的开头导入了那个类,我想它们不在同一个包中。