Java If statement trouble...

Associate
Joined
30 Dec 2005
Posts
415
Hey to all!

I may be doing something really stupid here but I can't see what it is at the moment (9 hours of Java has pretty much fried my brain!).

Basically, when I run the program i'm either typing in the command prompt:

java MyProgram

or

java MyProgram text


The problem occurs when the second one is executed. Although it detects that an arguement has been passed, the if statement fails to go to the TRUE block. Can anyone spot the problem?

Code:
public class MyProgram extends JFrame
{
	public static void main(String[] args)
	{
		String version = "gui";
		if (args.length > 0)
		{
			System.out.println(args[0]);
			[B]if(args[0]=="text")[/B]
			{
				version = "text";
				System.out.println("Launching text version...");
			}
			else
				System.out.println("Launching GUI version...");			
		}
		else
			System.out.println("Launching GUI version...");	

etc etc...

Btw, the code "System.out.println(args[0]);" does actually print "text" to the command prompt.


I appreciate any advice!

Cheers,
Rich
 
Ah cheers for that guys! I've had several scenarios where that would have been the cause of it, but never caught on that it was based on references.
 
Back
Top Bottom