Methoden Auf statische Methode einer anderen Klasse zugreifen, die Array zurückgibt

  • Themenstarter Themenstarter LucasBarrios
  • Beginndatum Beginndatum
L

LucasBarrios

Gast
Hi, ich bin noch Anfänger in Java. Ich möchte ein Programm schreiben, dass komplexe Rechenoperationen ausführt.

Java:
public class RLC {

	private static final Complex RESISTOR = new Complex(10, 0);
	private static final double INDUCTANCE = 0.01;
	private static final double CAPACITY = 0.00000001;
	private static double frequency[] = new double[10];
	private static double radialFrequency[] = new double[10];

	public static Complex[] calculateRofRLC() {
		Complex[] voltageResistor = new Complex[10];
		for (int index = 1; index <= 10; index++) {
			frequency[index - 1] = (10000 + (index * 1000));
			radialFrequency[index - 1] = (frequency[index - 1] * Math.PI * 2);
		}
		for (int index = 0; index < 10; index++) {
			voltageResistor[index] = voltageOverResistor(radialFrequency[index]);

		}
		return voltageResistor;
	}

	public static Complex voltageOverResistor(double radialFrequency) {

		Complex imaginary = new Complex(
				0,
				((radialFrequency * INDUCTANCE) - (1 / (radialFrequency * CAPACITY))));
		Complex impedance = Complex.add(RESISTOR, imaginary);
		Complex voltageOperating = new Complex(1, 0);
		Complex current = Complex.div(voltageOperating, impedance);
		Complex voltageResistor = Complex.mul(RESISTOR, current);

		return voltageResistor;
	}
}

Nun möchte ich aus einer anderen Klasse aus einer nicht-statischen Methode die Methode calculateRofRLC aufrufen und den zurückgegebenen Array speichern:

Java:
Complex[] test = RLC.calculateRofRLC();

Nur leider unterstrichelt er mir die Zeile mit:
Cannot make a static reference to the non-static method calculateRofRLC() from the type RLC

Ich hab im Internet leider keine Lösung für mein Problem gefunden, kann mir jemand helfen?
 
Sicher dass in deinem jetzigen Code die Zeile 9 so wirklich bei dir steht?(inkl. dem static)
Denn
Cannot make a static reference to the non-static method calculateRofRLC() from the type RLC
sagt ja scheinbar was anderes. Mal ein Project-clean o.ä. probiert?
 
Ja, das ist das was mich auch wundert. Es steht echt so da.

Mit Project Clean meinst du doch bestimmt die Funktion bei Eclipse
"Project" -> "Clean"
das hab ich mal gemacht(aller erstes Mal) und er unterstrichelt mir halt nur die Zeile mit

Cannot make a static reference to the non-static method calculateRofRLC(int) from the type RLC

Ist es denn syntaktisch eigentlich in Ordnung?
 
Komisch, Eclipse geschlossen, wieder geöffnet, Fehler weg. Danke erstmal 🙂
ich mach mal weiter und wenn sich wieder ws ergibt in der art, meld ich mich.
 

Neue Themen


Zurück
Oben