그래서 제가 가장 먼저 분명히하고 싶은 것은 이것이 제가보기에 실패한 제 오류라고 생각하지만 IDE가 IntelliJ라는 것을 아는 것이 도움이 될 수 있다고 생각했습니다. 또한 다른 오버플로 게시물 ( 질문 1 , 최종 키워드 , 질문 2) 을 살펴 보았지만 내가 말할 수있는 한 내 질문에 답변하지 않았습니다. 저는 CS 교육으로 AP 컴퓨터 과학 만 가지고 있었기 때문에 저의 지식은 매우 제한적입니다.
문제는 파일의 비공개 클래스에 있습니다. 2D 배열을 통해 경로를 생성하고 분기 효과를 위해 자체 인스턴스를 생성 할 수 있지만 반드시 그럴 필요는 없습니다. 또한 파일의 공용 클래스에 의해 여러 버전이 생성됩니다. 아래는 내 코드입니다 (내가 생각하는 부분은 관련이 있습니다. 더 필요한 경우 알려 주시면 내 질문을 업데이트하겠습니다). 더 필요한 것이 있으면 알려주세요. 도와 주셔서 감사합니다!
public class PathMaker
{
....
}
class RiverPath
{
private final int startID;
private final int endID;
private final double branchChance;
private final double endFactor;
public RiverPath(int x, int y, int[][] alts, double bChance, int c, double eFactor, int pX, int pY)
{
startID = MapNode.createID(x, y);
branchChance = bChance;
endFactor = eFactor;
...
endID = a number;
}
public RiverPath(int x, int y, int[][] alts, double bChance)
{
this(x, y, alts, bChance, 0, .02, -1, -1);
}
...
}
다른 생성자는 없으며 메서드 MapNode
가있는 또 다른 클래스입니다 public static int createID(int x, int y)
.
질문을 더 명확하게하기 위해해야 할 일이 있으면 알려주세요.
편집 : 4 가지 변수 모두 나에게 슬픔을주고있다. 또한 아래에 전체 생성자를 넣겠습니다. 내가 볼 수 return
있는 한 내 코드 에는 진술 이 없습니다 . 또한 오류는 컴파일하기 전에 발생하며
변수 [이름]이 초기화되지 않았을 수 있습니다.
이 4 가지 오류는 유일한 오류입니다. 생성자 외부에 정의 된 몇 가지 변수가 있습니다.
public RiverPath(int x, int y, int[][] alts, double bChance, int c, double eFactor, int pX, int pY)
{
count = c;
if(c > 0)
isBranch = true;
else
isBranch = false;//pX and pY only matter if is Branch
startID = MapNode.createID(x, y);
branchChance = bChance;
altitudes = alts;
endFactor = eFactor;
mainPath.add(new MapNode(x, y, altitudes));
boolean pathing = true;
MapNode currentNode = mainPath.get(0);
int[][] heights = new int[3][3];//heights around river
boolean[][] heightTight = new boolean[3][3];
int min;
int minCount;
int tID;
RiverPath branch;
while(pathing)
{
if(Math.random() < endFactor*count)
{
pathing = false;
}
else
{
count++;
min = 99;
minCount = 0;
for(int i = -1; i < 2; i++)
{//These loops fill heights with the nearby heights of mapnodes and set min as the min
for(int z = -1; z < 2; z++)
{
heights[i+1][z+1] = altitudes[currentNode.getY() + i][currentNode.getX() + z];
if(heights[i+1][z+1] < min)
{
min = heights[i + 1][z + 1];
}
}
}
if(min == currentNode.getAltitude())
{
min = 0;
for(int i = -1; i < 2; i++)
{
for(int z = -1; z < 2; z++)
{
tID = MapNode.createID(currentNode.getX() + z, currentNode.getY() + i);
if(heights[i+1][z+1] == currentNode.getAltitude() && (!isBranch || !(MapNode.createID(pX, pY) == tID)) && (mainPath.size() == 1 || mainPath.get(mainPath.size() - 1).getID() != tID))
{//if the altitude is the min, and it either isn't a branch or it isn't the node before this one
heightTight[currentNode.getY()+i][currentNode.getX()+z] = true;//a possible path exists here
min++;//min now keeps track of the total number of possible paths there are
minCount++;//also keeps track of total, but for a different implementation later
}
}
}
while(min != 0)
{
if(min == -1)
min = -2;//signals that we can test branches
for (int i = -1; i < 2; i++)
{
for (int z = -1; z < 2; z++)
{
if (min > 0 && heightTight[currentNode.getY() + i][currentNode.getX() + z] && Math.random() < 1.0/)//
{
if(min > 0)
min = -1;//signals that we can skip all other true values, but ONLY if there are more possible branches
else
min = 0;//in case we lower min below 0
}
else if(min == -2 && heightTight[currentNode.getY() + i][currentNode.getX() + z] && Math.random() < branchChance)//both random chance and it is a possible path
{
branch = new RiverPath(currentNode.getX() + z, currentNode.getY() + i, altitudes, branchChance, count, endFactor, currentNode.getX(), currentNode.getY());
branches.add(branch);
}
}
}
}
}
}
}
endID = currentNode.getID();
}
공유 한 스 니펫에서 벗어나 면 생성자 return
어딘가에 조건부 가 ...
있는 것 같습니다. 일찍 돌아 오므 endID
로 설정되지 않을 수 있습니다. 이것이이 오류의 일반적인 원인입니다.
편집하다:
게시 한 더 큰 코드 조각을 사용하면 IntelliJ에서 문제를 복제 할 수 있으며이 줄에 "Expression expected"라는 추가 오류가 표시됩니다.
if (min > 0 && heightTight[currentNode.getY() + i][currentNode.getX() + z] && Math.random() < 1.0 /)//
이 (특히 후행 /
후에는 1.0
) 당신의 진짜 문제가 될 것으로 보인다 -은 "초기화되지 않았"오류가 단순히, 부정되고 생성자의 증상이다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다