Compiler-Fehler Cannot make a static reference to the non-static field process

pi31415

Mitglied
Hallo wertes Forum,

ich verstehe den Fehler nicht, bzw. ich vermute das mein Objekt process nicht korrekt erzeugt wird.

Über einen Denkanstoß würde ich mich freuen!

Grüße aus Berlin,
Jan

2011-10-10_java_execprocess_eclipse_fail.jpg

Java:
package programmaufruf;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ExecProcess {
	Process process = null;
	//Process myobj = new Process(); //kann nicht instanziert werden?
	/*create a native process and return an instance of a subclass of Process 
	 * that can be used to control the process and obtain information about it
	 */
	public static void main(String[] args) {
		try {

			//process = Runtime.getRuntime().exec("ls -l"); //Unix		
			//process = Runtime.getRuntime().exec("command /c dir"); //Win9x
			process = Runtime.getRuntime().exec("cmd /c dir"); //Win NT
			BufferedReader input = new BufferedReader( new InputStreamReader (process.getInputStream()) );

			String output;
			while( (output = input.readLine()) != null ) {
				System.out.println(output);
			}
			
		}
		catch (Exception ex) {
			System.out.println(ex);
		}
		
	}
}
 
Hallo,

alle denkbaren compiler Fehler können mit einer Anfrage an google binnen nanosekunden gelöst werden.

Hier:
Code:
Process process = null;
==>
Code:
static Process process = null;

Ich überlasse es dem TO den Unterschied herauszufinden auf Seite 1 in jedem Javabuch.
 

Zurück
Oben