carookee - group communication for you
Home / JavaForum / Beginner
Infos   |   Features   |   Gold-Edition   |   Kundenservice   
java
  Übersicht
  Forum
Beginner
Java allgemein
JDBC
JNI
Networking
Online-Ressourcen
Swing + AWT
XML
Meckerecke
  Mitglieder
LOGIN





· Passwort vergessen
· Kostenlos anmelden
  Information
  Demo
  Features
  Im Vergleich
  Anmeldung
SUCHE
Beiträge, Foren oder Verfasser finden:
  Kundenservice
  Impressum
  Datenschutz
  AGB
Status
4.954 User online
1 User eingeloggt
 

Beiträge
   Antworten     Neuer Beitrag    

Beitrag 707 von 2963 (24%) |<   <   >   >|

Autor Gast
Datum 20.11.01, 08:58
Betreff Re: Can't make a static reference to nonstatic variable


anstelle klug über singleTon (wir sind bei Beginner!) zu Scheissen habe ich folgende Erklärung gefunden:
The issue is this: a static method means it belongs to the class, not each individual object. If you leave the static keyword off (the
usual case) as is done here with the method "myMethod()", it means that method can only be invoked on an object. But your call
from main() has not told myMethod() which object it is to be invoked on. Inside a non-static method, you don't have to provide
this information, as it assumes you mean the same object on which it was invoked. But when calling from a static method, you
must provide the information, and you haven't - hence the error message.

A common fix is to instantiate a member of the class, on which to invoke myMethod(), like this:


public static void main(String args[]) {

myclass m = new myclass();

m.myMethod();

}


Diskussionsverlauf:
    Re: Can't make a static reference to nonstatic variable
            Re: Can't make a static reference to nonstatic variable
            Re: Kommunikation zwischen zwei Klassen
        Re: Can't make a static reference to nonstatic variable
                    Re: Kommunikation zwischen zwei Klassen
    Re: Can't make a static reference to nonstatic variable
        Re: Can't make a static reference to nonstatic variable
            Re: Kommunikation zwischen zwei Klassen
                Re: Kommunikation zwischen zwei Klassen
        Kommunikation zwischen zwei Klassen
Can't make a static reference to nonstatic variable

 Auf diesen Beitrag antworten
 Neuen Beitrag verfassen


|<   <   >   >|

                                                                                                                                                                                                                           

Impressum  · Datenschutz  · AGB  · Infos  · Presse
Ein modernes Forum: teamturn.com