我不斷收到陣列尺寸失蹤錯誤陣列尺寸失蹤
public static Planet[] readPlanets(String filename) {
allPlanets = new Planet[];
In in = new In (filename);
int nplanets = in.readInt();
double radius = in.readDouble();
for (int i = 0; i < allPlanets.length; i++) {
double pxxPos = in.readDouble();
double pyyPos = in.readDouble();
double pxxVel = in.readDouble();
double pyyVel = in.readDouble();
double pmass = in.readDouble();
String pimgFileName = in.readString();
}
return allPlanets;
}
星球有六個維度,而我有多個行星
請張貼代碼*文字*,不是作爲一個屏幕截圖。這將有助於你展示你如何聲明'allPlanets',因爲我懷疑它實際上有6個維度... –
看起來'Planet'有一個維度,也許有六個元素? –