118551
Goto Top

If abfrage Schlägt immer fehl (JAVA)

Hallo ich habe Folgendes Problem

public Launcher(){
		
		OS = System.getProperty("os.name");  
		System.out.println(OS);
		
		if(OS == "Windows 7"){  
			StartLauncher();
		}else{
			JOptionPane.showMessageDialog(null, "Dein Betriebssystem (" + OS + ") wird nicht unterstüzt!", "Error", JOptionPane.OK_OPTION);  
		}
		
	}

diese if abfrage Schlägt immer fehl obwohl ich Window 7 Habe kann mir jemand sagen warum

Übrigens ist die Variable OS ist vom typ String

Danke im vorraus

LG DomiZone1

Content-Key: 272114

Url: https://administrator.de/contentid/272114

Printed on: April 24, 2024 at 09:04 o'clock

Member: the-datzl
Solution the-datzl May 15, 2015 updated at 18:24:46 (UTC)
Goto Top
Du testest mit ==, ob es sich bei den Strings um das gleiche Objekt handelt. Das funktioniert hier nicht!
Lösung:
if(OS.equals("Windows 7")){
...
}
Mitglied: 118551
118551 May 15, 2015 at 18:26:16 (UTC)
Goto Top
Danke für deine hilfe!

ich hatte bis jetzt es immer so das alles Auch Strings mit == ob sie gleich und der typ mit ===

(So kenn ichs)

LG DomiZone1