Well as I researched it seems to be a common error, but through the information I collected, it is mainly caused by the misbehaviour of main method, while in here I inspected nothing.
import java.util.Scanner;
public class NBody {
public static void main(double T, double dt, String filename) {
In f = new In(filename);
int N = f.readInt();
double R = f.readDouble();
Planet planets[] = new Planet[N];
for (int i = 0; i < N; i++) {
planets[i] = getPlanet(f);
}
StdDraw.setScale(-R, R);
for (Planet star:planets) {
star.draw();
}
/*
for (Planet star:planets) {
star.update(dt);
StdDraw.picture(star.x, star.y, star.imgName);
}
*/
}
public static Planet getPlanet(In file) {
double x = file.readDouble();
double y = file.readDouble();
double xVelocity = file.readDouble();
double yVelocity = file.readDouble();
double mass = file.readDouble();
String imgName = file.readString();
Planet p = new Planet(x, y, xVelocity, yVelocity, mass, imgName);
return p;
}
}
So how can I solve this problem? I didn't transfer any arguments to it and the java NBody just fails (I compiled successfully, I could assure that).
Your
main
method has the wrong signature. To be an entry point for a Java application, it must have a single parameter of typeString[]
(and avoid
return type, and it must be public and static):or
The parameter name is unimportant.
You'll need to parse the command line arguments into appropriate types, e.g.