Cannot make a static reference to the non-static field

Status
Nicht offen für weitere Antworten.

T1M

Bekanntes Mitglied
Hey,
ich bekomm diesen Fehler.
Versuche in meiner Hauptklasse was einzubringen, was aus einer anderen klasse kommt.

mal n bisl code zum leichteren verständnis.
will in ner jtable eine zeile nach oben verschieben.
Code:
//zeile nach oben verschieben
        pat_up.addActionListener(new MoveListener(table, MoveListener.MOVE_UP));
und die klasse MoveListener:
Code:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class MoveListener implements ActionListener {
	public  int MOVE_UP = -1;
	public  int MOVE_DOWN = 1;
	/**
	 * @param table
	 */
	public MoveListener(JTable table, int direction) {
		myTable = table;
		this.direction = direction;
	}

	JTable myTable = null;
	public int direction = MOVE_UP;
	
	/**
	 * The actual move action. based on the direciton,
	 * calculate the destination row and simply call the
	 * moveRow method. then call a method to set the 
	 * row as currently selected row.
	 */
	public void actionPerformed(ActionEvent arg0) {
		int selRow = myTable.getSelectedRow();
		//find the destination row.
		int destRow = selRow + direction;
		//check if the destination row is within table limits
		if (destRow >= 0 && destRow < myTable.getRowCount()) {
			DefaultTableModel dtm = (DefaultTableModel) myTable.getModel();
			dtm.moveRow(selRow, selRow, destRow);
			//Move is done, now set selection.
			myTable.setColumnSelectionAllowed(false);
			myTable.setRowSelectionAllowed(true);
			myTable.setRowSelectionInterval(destRow, destRow);
			//make the change visible in UI.
			myTable.repaint();
		}
	}
}

der fehler wird angezeigt bei dem konstruktor
Code:
pat_up.addActionListener(new MoveListener(table, MoveListener.MOVE_UP));
genauer:
Code:
MoveListener.MOVE_UP
da unterstreicht er mirs rot und sagt halt: 'Cannot make a static reference to the non-static field'

THX anyway,
T1M
 

T1M

Bekanntes Mitglied
äh, ja gut, hab ich dann auch noch gefunden. aber bringt mich net wirklich weiter ... :(
 

T1M

Bekanntes Mitglied
wie ich das
Code:
pat_up.addActionListener(new MoveListener(table, MoveListener.MOVE_UP));
ändern muß. ich kann ja nich einfach noch was in den konstruktor dazuschreiben.
 

Wildcard

Top Contributor
Code:
   public  static final int MOVE_UP = -1;
   public  static final int  MOVE_DOWN = 1;
 
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
R Cannot make a static reference to the non-static method Java Basics - Anfänger-Themen 5
L [Gelöst] Cannot make a static reference ... Java Basics - Anfänger-Themen 12
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