Method undefinded for "Klasse"

Status
Nicht offen für weitere Antworten.
S

Samuel

Gast
Also ich bin kein Anfänger im Programmieren, aber ein Anfängerin Java.
Ich habe eine Klasse
Mitarbeiter und ich habe eine Klasse ExtMitarbeiter, die von Mitarbeiter erbt.
Groß aussehen tuts so:
Code:
public class Mitarbeiter {
	//Variablen;
	String name;
	String abtl;
	Fahrt dienstF = null;
//Konstruktoren usw
}

Code:
public class ExtMitarbeiter extends Mitarbeiter{

	public boolean unterwegs(){
		return dienstF==null?false:true;
	}


}
Im Grunde hab ich nur Mitarbeiter um get und set Methoden der Variablen erweitert
(Ich weiß, die Variablen sind hier ja noch public, aber Kapselung hatte mein Prof nicht, also muss ich publich nehmen :( )

Nun hab ich eine Fuhrpark Klasse mit main:
Code:
public class Fuhrpark {
	//Erweiterung, weil Getties und Setties fehlen
	ExtMitarbeiter[] m = new ExtMitarbeiter[1];

	
	public Fuhrpark(){
		//Anlegen der Daten
		m[0] = new ExtMitarbeiter("Mueller","E");
		
		
	}
	
	public static void main(String[] args){
		//Zuerst eine Fuhrparkinstanz
		Fuhrpark fp = new Fuhrpark(); //Konstruktor aufrufen;
		//Interface einbauen, auswahl der Leute und Autos variabel
		
		optionen(0,fp);
		
	}
	public static void print(String str, boolean ln){
		if (ln){
		System.out.println(str);
		}else {
		System.out.print(str);	
		
		}
		
	}
	
	public static void optionen(int u, Fuhrpark fp){
		
		if (fp.m[u].unterwegs())  //<----------------- Fehler

	}
}

Das ist eigentlich ganz simpel, aber ich bekomme:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method unterwegs() is undefined for the type Mitarbeiter

at Fuhrpark.optionen(Fuhrpark.java:48)
Nun weiß ich garnicht, was der von mir will, Datentyp m ist ja kein Mitarbeiter, sondern ExtMitarbeiter, welcher die Methode unterwegs kennen sollte, aber er tut es nicht, obwohl ich hier keinmal Mitarbeiter irgendwohin zuweise
 

André Uhres

Top Contributor
Vorerst: ein ExtMitarbeiter ist immer auch ein Mitarbeiter (Vererbung !).
Ich bekomme allerdings kein Fehler:
Code:
/*
 * Fuhrpark.java
 */
package schnipsel;
public class Fuhrpark {
    public Fuhrpark() {
        //Anlegen der Daten
        m[0] = new ExtMitarbeiter("Mueller","E");
    }
    public static void print(String str, boolean ln){
        if (ln){
            System.out.println(str);
        }else {
            System.out.print(str);
        }
    }
    public static void optionen(int u, Fuhrpark fp){
        if (fp.m[u].unterwegs())  //<----------------- Fehler
            System.out.println("unterwegs");
        else
            System.out.println("nicht unterwegs");
    }
    public static void main(String[] args){
        //Zuerst eine Fuhrparkinstanz
        Fuhrpark fp = new Fuhrpark(); //Konstruktor aufrufen;
        //Interface einbauen, auswahl der Leute und Autos variabel
        optionen(0,fp);
    }
    //Erweiterung, weil Getties und Setties fehlen
    ExtMitarbeiter[] m = new ExtMitarbeiter[1];
}
class Mitarbeiter {
    //Variablen;
    String name;
    String abtl;
    Fahrt dienstF = null;
//Konstruktoren usw
}
class ExtMitarbeiter extends Mitarbeiter{
    public ExtMitarbeiter(String s1, String s2){
    }
    public boolean unterwegs(){
        return dienstF==null?false:true;
    }
}
class Fahrt{
}
 
S

Samuel

Gast
Das ist es ja, Eclipse ist auch ganz friedlich, ich kann es auch starten, wenn ich aber bis zu der Stelle komme, krieg ich den Compiler Fehler und eben nicht sofort
 
S

Samuel

Gast
Ja, das war es, habs noch vorhin selber getestet, dämliches Ding, normalerweise klappt sowas doch problemlos.

Aber danke für die Hilfe :)
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
R finaler Wert in outerMethod von method in InnerMethodClass Java Basics - Anfänger-Themen 2
S Methoden 2 non-static Methoden, trotzdem Fehler "non static method can not be referenced from a static context" Java Basics - Anfänger-Themen 9
P myClass?.method() in Java Java Basics - Anfänger-Themen 4
T setFill method Java Basics - Anfänger-Themen 3
H Methode mit Array als Rückgabe This method must return a result of Type int[] Java Basics - Anfänger-Themen 2
N The method setSaldo(double) in the type Konto is not applicable for the arguments (int, int) Java Basics - Anfänger-Themen 2
A startsWith method und substring Java Basics - Anfänger-Themen 2
W Remote Method Invocation RMI - Problem Java Basics - Anfänger-Themen 0
I Java Generics factory method Java Basics - Anfänger-Themen 2
V the static method should be accessed is a static way Java Basics - Anfänger-Themen 6
N Erste Schritte "non-static method" oder "XYZ can not be resolved" Java Basics - Anfänger-Themen 21
K Eigene Annotations, Pre-/Post-/Call-Method Java Basics - Anfänger-Themen 6
B Threads Thread sleep() Method einfache Frage Java Basics - Anfänger-Themen 8
G Was als main Method Java Basics - Anfänger-Themen 6
M Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 10
E Array to String Method Reverse Java Basics - Anfänger-Themen 5
D Methoden undefined method Java Basics - Anfänger-Themen 13
S Method mit Eingabe abrufen Java Basics - Anfänger-Themen 1
D Interface Amazon Skill Kit, Interface but method in other class? Java Basics - Anfänger-Themen 3
U Method References Java Basics - Anfänger-Themen 1
UnityFriday method getPrevious in class List<ContentType> cannot be applied to given types Java Basics - Anfänger-Themen 29
P Variablen einer Methode in andere Method übergeben Java Basics - Anfänger-Themen 6
B Methoden The method mirror(double[]) in the type Convolution is not applicable for the arguments (double) Java Basics - Anfänger-Themen 8
J easy remove method Java Basics - Anfänger-Themen 1
M abstract method does not override or implement.... Java Basics - Anfänger-Themen 7
R The method printf(String, Object[]) in the type printStrem in not applicable for the arguments ... Java Basics - Anfänger-Themen 3
M Deklaration und Initialisierung bei Method Erstellung Java Basics - Anfänger-Themen 12
K Variablen RETURN in Case-Switch / This method must return a result of type Item Java Basics - Anfänger-Themen 4
W Compiler-Fehler "non-static method cannot be referenced"-Problem Java Basics - Anfänger-Themen 6
K String equalIgnoreCase() Method Java Basics - Anfänger-Themen 19
E non-static method und static context Java Basics - Anfänger-Themen 15
L Command Prompt / Main Method / String Java Basics - Anfänger-Themen 9
M Methoden "Non-static method xy cannot be referenced from a static context" Java Basics - Anfänger-Themen 20
T selection method does not contain a main type Java Basics - Anfänger-Themen 7
U UML Factory Method Java Basics - Anfänger-Themen 4
R Compiler-Fehler Cannot find symbol (Method printIn) Java Basics - Anfänger-Themen 3
H non-static method cannot be referenced from a static context Java Basics - Anfänger-Themen 2
L Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 6
B Object "Method" in TreeSet, Fehler beim Vergleichen/Comparable Java Basics - Anfänger-Themen 9
M Problem mit Static Method Java Basics - Anfänger-Themen 8
W Main-method in Object-classes Java Basics - Anfänger-Themen 5
J Compiler findet method nicht Java Basics - Anfänger-Themen 12
M This method must return a result of type int Java Basics - Anfänger-Themen 13
M Fehlermeldung: the method.... ist undefined for the type object Java Basics - Anfänger-Themen 6
S this method must return a result of type double Java Basics - Anfänger-Themen 2
G Collections.binarySearch(LinkedList): cannot find method Java Basics - Anfänger-Themen 6
Y Theorie: Abstract Method Java Basics - Anfänger-Themen 6
C Methoden numberField.getDouble no such method error Java Basics - Anfänger-Themen 4
F Mal wieder: Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 9
F Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 3
Q non-static method blub cannot be referenced from a static context Java Basics - Anfänger-Themen 6
E Netbeans, "class does not have a main method" Java Basics - Anfänger-Themen 8
L no such method error: main() Java Basics - Anfänger-Themen 2
O Abstract Method & Generics Java Basics - Anfänger-Themen 10
N public class -> public method -> variable private? Java Basics - Anfänger-Themen 10
R Could not find main method Java Basics - Anfänger-Themen 3
U Boolean istGleich() Method Java Basics - Anfänger-Themen 15
Luk10 method () not found Java Basics - Anfänger-Themen 9
A OOP Fehler non-static method can not be[...] Java Basics - Anfänger-Themen 2
N Reference to non-static method Java Basics - Anfänger-Themen 8
G non static method scale(int,int) cannot be referenced from a static context Java Basics - Anfänger-Themen 16
A The method getYear() from the type Date is deprecated Java Basics - Anfänger-Themen 6
A cannot find symbol - symbol : method Java Basics - Anfänger-Themen 5
S The method readInt() Problem Java Basics - Anfänger-Themen 5
E method undefined - wo ist der Fehler? Java Basics - Anfänger-Themen 5
J non static method cannot be referenced from static context Java Basics - Anfänger-Themen 7
L cannot find symbol-method Java Basics - Anfänger-Themen 3
D kleine Passwortabfrage erstellen incl. Method zum verändern Java Basics - Anfänger-Themen 7
S Mein Quicksort Problem: he method quickSort(int[], int, int) Java Basics - Anfänger-Themen 2
M Invalid Method Java Basics - Anfänger-Themen 7
F does not overwride abstract method Java Basics - Anfänger-Themen 2
C Fehler: non-static method Java Basics - Anfänger-Themen 5
B method intValue() is undefined for the type String (?) Java Basics - Anfänger-Themen 4
R Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 5
G String zu Method Java Basics - Anfänger-Themen 11
B cannot find symbol method equalsIgnoreCase? Java Basics - Anfänger-Themen 23
T Does not have a main method ? GGT. Java Basics - Anfänger-Themen 4
N invalid method declaration; return type required Java Basics - Anfänger-Themen 4
T this method.is not visible Java Basics - Anfänger-Themen 3
C overridden method does not throw java.io.IOException Java Basics - Anfänger-Themen 4
R non-static method execute Java Basics - Anfänger-Themen 3
J Morgen Java-Klausur. Stack, Heap, Method-Area Java Basics - Anfänger-Themen 2
V Non Static Method. Java Basics - Anfänger-Themen 2
R Eclipse: This method must return a result of type double. Java Basics - Anfänger-Themen 2
M Fehlermeldung (The method contains(String) is. Java Basics - Anfänger-Themen 3
M Fehlermeldung (the method add(OE) in the type Abteilung.) Java Basics - Anfänger-Themen 2
N ActionListener versch. Buttons zuweisen => versch. Method Java Basics - Anfänger-Themen 13
T method <init> not found in class . Java Basics - Anfänger-Themen 4
G Problem (oder Verständnisporblem) bei einer static method Java Basics - Anfänger-Themen 9
frau-u Altes Problem: non-static method cannot be reference Java Basics - Anfänger-Themen 7
M Solaris - Method Split Fehler Java Basics - Anfänger-Themen 2
M method xxx() from the type xxx is deprecated Java Basics - Anfänger-Themen 3
A Method.invoke() mit geerbten Methoden Java Basics - Anfänger-Themen 2
A The method getClass() from the type saveLog is not static Java Basics - Anfänger-Themen 2
G Abstract Class - Abstract Method Java Basics - Anfänger-Themen 4
R Could not find Main-Method Java Basics - Anfänger-Themen 4
I @Inject in normaler Klasse? Java Basics - Anfänger-Themen 4
P Enum oder normale Klasse? Java Basics - Anfänger-Themen 10
P Meldung aus Java-Klasse in Thread an aufrufende Klasse Java Basics - Anfänger-Themen 1
P Wie kann ich meine Keylistener Klasse unterscheiden lassen, von welcher "Quelle" der Input kommt? Java Basics - Anfänger-Themen 2

Ähnliche Java Themen

Neue Themen


Oben