gpt4 book ai didi

Java stackOverFlow 错误对象的编码方式不正确

转载 作者:行者123 更新时间:2023-12-01 18:35:13 25 4
gpt4 key购买 nike

我正在开发一个运输 map 项目。我为该位置创建了一个名为 Chart 的对象和一个名为 Pos 的对象。我无法开始工作的是,当我从文本文件读取图表以正确创建对象 Pos 时,因为这就是失败的地方。

现在这是 Pos 类

 private Pos Pos;

public Pos(int d, int m, int t){
Pos pos = new Pos(d,m,t);
}

现在这是图表类

private String title;
private String colorString;
private String scale;
private String edition;
private Pos north;
private Pos south;
private Pos west;
private Pos east;

private Chart Chart;

public Chart(Pos north, Pos south, Pos west, Pos east, String color, String scale, String edition, String title){
Chart = new Chart(north, south, west, east, color, scale, edition, title);
}

现在这是我想要创建图表的代码的地方。我已经采取了很多小步骤来确保输出正确:

In in;
String fileName = "charts.txt";
int aantalKaarten;
int kolommen;
String[][] tabel;
int n1,n2,n3,s1,s2,s3,w1,w2,w3,e1,e2,e3;
String color;
String edition;
String scale;
String title;

in = new In(fileName);
aantalKaarten = in.readInt()+1;
for(int i = 0;i < aantalKaarten;i++){
try {
n1 = in.readInt();
n2 = in.readInt();
n3 = in.readInt();
System.out.println("Noordelijke lengtegraad: " + n1 + ", " + n2 + ", " + n3);
s1 = in.readInt();
s2 = in.readInt();
s3 = in.readInt();
System.out.println("Zuidelijke lengtegraad: " + s1 + ", " + s2 + ", " + s3);
w1 = in.readInt();
w2 = in.readInt();
w3 = in.readInt();
System.out.println("westelijke breedtegraad: " + w1 + ", " + w2 + ", " + w3);
e1 = in.readInt();
e2 = in.readInt();
e3 = in.readInt();
System.out.println("oostelijke breedtegraad: " + e1 + ", " + e2 + ", " + e3);
color = in.readString();
System.out.println("De kleur van de kaart: " + color);
edition = in.readString();
System.out.println("Editie: " + edition);
scale = in.readString();
System.out.println("Schaal: " + scale);
title = in.readLine();
System.out.println("Kaart: " + title);
System.out.println("");
Pos north = new Pos(n1,n2,3);
Pos south = new Pos(s1,s2,s3);
Pos west = new Pos(w1,w2,w3);
Pos east = new Pos(e1,e2,e3);
Chart chart = new Chart(north, south, west, east, color, scale, edition, title);
}
catch(NoSuchElementException eNSEE){
System.out.println("No such element exception");
}
}
in.close();

我真的希望能得到一些帮助,因为我陷入了绝望的困境。可能对位置所做的更改我也必须更改图表,因为构建是相同的

预先感谢您的帮助。

编辑:这是我正在处理的文本文件

 20
51 53 00 3 49 00 51 49 70 3 59 00 B ed:2011/2012 1:50.000 ANWB Z 5
51 53 00 3 59 00 51 49 70 4 09 15 B ed:2011/2012 1:50.000 ANWB Z 6
51 49 50 3 28 90 51 42 10 3 49 00 B ed:2011/2012 1:50.000 ANWB Z 7-8
51 49 50 3 49 00 51 42 10 4 09 00 B ed:2011/2012 1:50.000 ANWB Z 9-10
51 41 80 3 19 20 51 34 00 3 39 60 B ed:2011/2012 1:50.000 ANWB Z 11-12
51 42 20 3 39 40 51 34 40 3 59 70 B ed:2011/2012 1:50.000 ANWB Z 13-14
51 42 40 3 59 70 51 34 60 4 19 80 B ed:2011/2012 1:50.000 ANWB Z 15-16
51 42 60 4 19 60 51 34 80 4 29 80 B ed:2011/2012 1:50.000 ANWB Z 17
51 34 20 3 19 80 51 26 80 3 39 90 B ed:2011/2012 1:50.000 ANWB Z 19-20
51 34 60 3 39 80 51 26 80 4 00 00 B ed:2011/2012 1:50.000 ANWB Z 21-22
51 34 60 3 59 70 51 27 20 4 20 00 B ed:2011/2012 1:50.000 ANWB Z 23-24
51 26 70 3 20 00 51 19 00 3 40 20 B ed:2011/2012 1:50.000 ANWB Z 25-26
51 27 00 3 40 00 51 19 40 4 00 00 B ed:2011/2012 1:50.000 ANWB Z 27-28
51 27 15 4 00 00 51 19 60 4 20 20 B ed:2011/2012 1:50.000 ANWB Z 29-30
51 27 60 2 28 60 51 00 00 2 58 40 G ed:2012 1:100.000 Hydro 1801.2
51 32 00 2 51 60 51 13 70 3 36 00 G ed:2012 1:100.000 Hydro 1801.3
51 30 50 3 22 50 51 20 50 3 44 30 G ed:2012 1:50.000 Hydro 1801.4
51 48 60 3 00 00 51 30 40 3 40 00 G ed:2012 1:100.000 Hydro 1801.5
52 00 06 3 23 00 51 42 40 4 07 20 G ed:2012 1:100.000 Hydro 1801.6
52 15 60 3 46 40 51 57 60 4 29 60 G ed:2012 1:100.000 Hydro 1801.7

最佳答案

你的代码

public Pos(int d, int m, int t){
Pos pos = new Pos(d,m,t);
}

当这段代码运行时,它会递归地调用Pos构造函数本身,因此它会被堆栈并调用内部Pos(),那么StackoverFlowException就不会那么奇怪了。

你的类(class)应该是

class Pos {
int d;
int m;
int t;

public Pos(int d, int m, int t) {
this.d = d;
this.m = m;
this.t = t;
}
}

关于Java stackOverFlow 错误对象的编码方式不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com