Cannot make a static reference to the non-static method

Status
Nicht offen für weitere Antworten.

Raorkon

Mitglied
Hallo zusammen

ich habe folgendes Problem:

ich will die Eingabe eines Monatsnamen überprüfen und das will ich übungstechnische in einer anderen Klasse machen. dazu habe ich folgendes Programm geschrieben:

Code:
package maz;

import java.io.StreamTokenizer;

public class maz_start 
{
	public static void main(String[] args) 
	{	

		berechneMAZ test = new berechneMAZ();
		pruefen test1 =new pruefen();
		String monat="";
		int jahr=0;
		try{
			System.out.println("Geben Sie den Monat und das Jahr an: (MM JJJJ)");
			StreamTokenizer eingabe=new StreamTokenizer(System.in);
			eingabe.nextToken();
			monat=eingabe.sval;
			if(pruefen.pruefe(monat))
			eingabe.nextToken();
			jahr=(int)eingabe.nval;
			}
		catch(Exception e){System.out.println("fehlerhafte Eingabe");}
		berechneMAZ.rechnen(jahr,monat);
	}

}

Code:
package maz;

public class pruefen 
{
	public boolean pruefe(String pmonat)
	{
		String mon_name[]={"Januar","Februar","März","April","Mai","Juni","July","August","September","Oktober","November","Dezember"};
		int k=0;
		for (int i=0;i<12;i++)
		{
[quote]			if(pmonat.compareTo(mon_name[i])<0)
			{k=1;break;}
		}
		if(k==1)
			return true;
		else
			return false;[/quote]
	}
}

nun erhalte ich den Fehler:
Cannot make a static reference to the non-static method pruefe(String) from the type pruefen
Leider weiß ich nicht was ich falsch mache :(

Ich habe sage doch das ich nen Boolean zurückerwarte. Bitte nicht den restlichen Programmtext kritisieren, das ist alles nur zur Übung :)
Wobei ich doch noch ne Frage dazu hätte:
Code:
			if(pmonat.compareTo(mon_name[i])<0)
			{k=1;break;}
		}
		if(k==1)
			return true;
		else
			return false;
da gibt es bestimmt ne sinnvoller Methode oder?

thx schon mal im vorraus
 

fehlerfinder

Bekanntes Mitglied
Raorkon hat gesagt.:
Cannot make a static reference to the non-static method
Vielleicht noch kurz zum Hintergrund:
Der Aufruf von "pruefe" erfolgt aus main() und main ist als "static" definiert. "pruefe" hingegen ist nicht als "static" definiert und genau darauf weist dich diese Fehlermeldung hin (was natürlich nix an der Korrektheit des Beitrags von "Der Müde Joe" ändert ;-) )
 

Der Müde Joe

Top Contributor
fehlerfinder hat gesagt.:
Raorkon hat gesagt.:
Cannot make a static reference to the non-static method
Vielleicht noch kurz zum Hintergrund:
Der Aufruf von "pruefe" erfolgt aus main() und main ist als "static" definiert. "pruefe" hingegen ist nicht als "static" definiert und genau darauf weist dich diese Fehlermeldung hin

:noe:

"pruefe" ist nicht statisch, darum kann man es auch nicht über den Klassennamen aufrufen (Klasse.methode() ).
Ob in statischer Methode oder sonst wo ist egal.
 

fehlerfinder

Bekanntes Mitglied
Der Müde Joe hat gesagt.:
fehlerfinder hat gesagt.:
Vielleicht noch kurz zum Hintergrund:
Der Aufruf von "pruefe" erfolgt aus main() und main ist als "static" definiert. "pruefe" hingegen ist nicht als "static" definiert und genau darauf weist dich diese Fehlermeldung hin
"pruefe" ist nicht statisch, darum kann man es auch nicht über den Klassennamen aufrufen (Klasse.methode() ).
Ob in statischer Methode oder sonst wo ist egal.
Jo - so wird's klarer. Stimmt - dass main() static ist, ist egal :oops:
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
M Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 10
A Cannot make a static reference to the non-static field Java Basics - Anfänger-Themen 6
L Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 6
K Variablen Cannot make a static reference to the non-static field time Java Basics - Anfänger-Themen 6
P Compiler-Fehler Cannot make a static reference to the non-static field process Java Basics - Anfänger-Themen 3
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
B Cannot make a static reference...?? Java Basics - Anfänger-Themen 5
B Mal wieder "cannot make a static reference..." Java Basics - Anfänger-Themen 2
L [Gelöst] Cannot make a static reference ... Java Basics - Anfänger-Themen 12
T Cannot make a static reference to the non-static field Java Basics - Anfänger-Themen 8
frau-u Altes Problem: non-static method cannot be reference Java Basics - Anfänger-Themen 7
J Fehlermeldung unklar. non-static variable player0 cannot be referenced from a static context Java Basics - Anfänger-Themen 4
P non-static variable cannot be referenced from a static context Java Basics - Anfänger-Themen 6
Aprendiendo Interpreter-Fehler "non-static variable this cannot be referenced from a static context" Java Basics - Anfänger-Themen 2
H Variablen error: non-static variable cannot be referenced from a static context Java Basics - Anfänger-Themen 4
U Erste Schritte cannot be referenced from a static context Java Basics - Anfänger-Themen 1
W Compiler-Fehler "non-static method cannot be referenced"-Problem Java Basics - Anfänger-Themen 6
M Methoden "Non-static method xy cannot be referenced from a static context" Java Basics - Anfänger-Themen 20
K Objekt erstellen - error: non-static variable this cannot be referenced from a static context Java Basics - Anfänger-Themen 17
H non-static method cannot be referenced from a static context Java Basics - Anfänger-Themen 2
N cannot referenced from static context Java Basics - Anfänger-Themen 5
Q non-static method blub cannot be referenced from a static context Java Basics - Anfänger-Themen 6
N non-static variable con cannot be referenced from a static context Java Basics - Anfänger-Themen 7
G non static method scale(int,int) cannot be referenced from a static context Java Basics - Anfänger-Themen 16
J non static method cannot be referenced from static context Java Basics - Anfänger-Themen 7
P Problem mit Thread - cannot be referenced from a static cont Java Basics - Anfänger-Themen 5
W Cannot find Symbol Java Basics - Anfänger-Themen 5
M NullPointerException: Cannot read the array length because "this.Kinder" is null Java Basics - Anfänger-Themen 1
D Cannot find JUnit.framework Java Basics - Anfänger-Themen 1
W Cannot resolve symbol 'HttpServlet' Java Basics - Anfänger-Themen 2
I JSON - cannot deserialize from Object value Java Basics - Anfänger-Themen 16
J Scanner cannot be resolved to a type Java Basics - Anfänger-Themen 3
N Fehler "Cannot instantiate the type" Java Basics - Anfänger-Themen 3
jakobfritzz Array- cannot invoke "" because "" is null Java Basics - Anfänger-Themen 4
Flo :3 Variablen Type dismatch: cannot convert from string to int Java Basics - Anfänger-Themen 9
C system cannot be resolved Fehler in Eclipse Java Basics - Anfänger-Themen 18
V ClientProtocolException cannot be resolved Java Basics - Anfänger-Themen 6
A Cannot find symbol mit Konstruktoren Java Basics - Anfänger-Themen 27
A Cannot find symbol bei exceptions Java Basics - Anfänger-Themen 2
J The import org.bukkit cannot be resolved Java Basics - Anfänger-Themen 3
L cannot find symbol variable Kon Java Basics - Anfänger-Themen 8
L constructor cannot be applied... Java Basics - Anfänger-Themen 22
F Erste Schritte error: cannot find symbol Java Basics - Anfänger-Themen 5
P a cannot be resolved bei einer do while Schleife Java Basics - Anfänger-Themen 1
R return: cannot find symbol Java Basics - Anfänger-Themen 2
L Bluej Error: Cannot find Symbol Java Basics - Anfänger-Themen 13
M Iterator cannot refer to a non final... Java Basics - Anfänger-Themen 20
S Cannot find symbol (symbol ist eine Variable) Java Basics - Anfänger-Themen 13
N Cannot find symbol Java Basics - Anfänger-Themen 18
T Error: int cannot be dereferenced Java Basics - Anfänger-Themen 10
J JLabel cannot be resolved Java Basics - Anfänger-Themen 8
P Cannot find symbol, wieso? Java Basics - Anfänger-Themen 5
UnityFriday method getPrevious in class List<ContentType> cannot be applied to given types Java Basics - Anfänger-Themen 29
M Erste Schritte cannot find symbol - Probleme mit Klassen Java Basics - Anfänger-Themen 6
B OOP next cannot be resolved or is not a field Java Basics - Anfänger-Themen 6
B OOP Cannot instantiate the type AuDList<Integer> Java Basics - Anfänger-Themen 18
J Error: cannot find symbol - variable Java Basics - Anfänger-Themen 3
D Java Eclipse cannot be cast to java.awt.event.ItemListener Java Basics - Anfänger-Themen 3
F Erste Schritte parseint: cannot find symbol Java Basics - Anfänger-Themen 6
J Fehlermeldung : cannot invoke char(at) int on the primitive type int --- Anfänger Java Basics - Anfänger-Themen 5
M Erste Schritte [Variable] cannot be resolved to a variable Java Basics - Anfänger-Themen 4
M The Selection cannot be launched... Java Basics - Anfänger-Themen 4
M Vererbung - Cannot Find Symbol constructor... Java Basics - Anfänger-Themen 11
D error: cannot find symbol Java Basics - Anfänger-Themen 3
B Frage zu Beispielprogramm: "error: cannot find symbol" Java Basics - Anfänger-Themen 2
M Methoden Cannot be resolved to a variable Java Basics - Anfänger-Themen 5
BlueMountain Erste Schritte error: cannot find symbol Java Basics - Anfänger-Themen 2
P enum: cannot be resolved to a type Java Basics - Anfänger-Themen 2
L Error: Cannot find symbol Java Basics - Anfänger-Themen 1
W int cannot be dereferenced Java Basics - Anfänger-Themen 5
P Cannot find Symbol Java Basics - Anfänger-Themen 3
K Compiler-Fehler Button cannot be resolved or is not a field Java Basics - Anfänger-Themen 6
F Methoden Cannot refer to a non-final variable.. verständnisproblem. Java Basics - Anfänger-Themen 7
K The Java Runtime Environment cannot be found. Java Basics - Anfänger-Themen 6
F Input/Output IOTools Fehlermeldung: cannot be resolved Java Basics - Anfänger-Themen 16
L Cannot Find Symbol - Was soll denn das bedeuten?!? Java Basics - Anfänger-Themen 7
P StdIn.readDouble: cannot find symbol Java Basics - Anfänger-Themen 7
B Fehler "Cannot find symbol - variable number1" Java Basics - Anfänger-Themen 13
P Variablen Cannot be resolved to a variable Java Basics - Anfänger-Themen 8
B Compiler-Fehler cannot find symbol Java Basics - Anfänger-Themen 6
K Date cannot be cast to java.lang.Integer Java Basics - Anfänger-Themen 4
T Cannot convert from Integer to int Java Basics - Anfänger-Themen 12
K Cannot find symbol Java Basics - Anfänger-Themen 3
H cannot find symbol Java Basics - Anfänger-Themen 4
S cannot find symbol, symbol: constructor Java Basics - Anfänger-Themen 2
3 Compiler-Fehler Fehlerbehebung cannot find Symbol Java Basics - Anfänger-Themen 4
R Compiler-Fehler Cannot find symbol (Method printIn) Java Basics - Anfänger-Themen 3
M Meldung "cannot convert flom boolean to boolean[]" Java Basics - Anfänger-Themen 3
B Polymorphie A obj = new B; "cannot find symbol app()" Java Basics - Anfänger-Themen 5
S wieso Fehlermeldung cannot find symbol hier Java Basics - Anfänger-Themen 10
T Cannot refer to an instance field xxx while explicitly invoking a constructor Java Basics - Anfänger-Themen 14
T Cannot find Symbol(String) Java Basics - Anfänger-Themen 9
C cannot convert from int to boolean Java Basics - Anfänger-Themen 3
2 Compiler-Fehler cannot find symbol Java Basics - Anfänger-Themen 13
N Erste Schritte import javax.media.3d....; //Fehlermeldung: cannot be resolved Java Basics - Anfänger-Themen 10
B Erste Schritte cannot find symbol - problem Java Basics - Anfänger-Themen 9
K int cannot be dereferenced Java Basics - Anfänger-Themen 2
H LocationReferenceImpl cannot be resolved to a type Java Basics - Anfänger-Themen 5
D Cannot find symbol variable Java Basics - Anfänger-Themen 9

Ähnliche Java Themen

Neue Themen


Oben