954,536 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem returning a boolean value.

Hi I am trying to return a boolean value into another method, but it's not working.

public static boolean ItemFound(boolean item, String desc1, String desc2, JTextArea txt){
        	
 		      if(item == true)
		     		txt.setText(desc1);
	      	if(item == false){
						txt.setText(desc2);
						item = true;
						}
						return item;
        	
        }


and inside the other method I have

new ItemFound(pistol, "No other items found in Bedroom", "You found Pistol", txt);


the error I get is:
cannot find symbol constructor ItemFound(boolean,java.lang.String,java.lang.String,javax.swing.JTextArea)

FancyShoes
Newbie Poster
11 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

You're trying to call the static method as if it is a constructor.

http://leepoint.net/notes-java/flow/methods/50static-methods.html

Read the section on calling static methods.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

static methods should be called like this...
ClassName.MethodName(params);
while your approach is trying to call the constructor.
it will be ....
className.ItemFound(pistol, "No other items found in Bedroom", "You found Pistol", txt);
Hi I am trying to return a boolean value into another method, but it's not working.

public static boolean ItemFound(boolean item, String desc1, String desc2, JTextArea txt){
        	
 		      if(item == true)
		     		txt.setText(desc1);
	      	if(item == false){
						txt.setText(desc2);
						item = true;
						}
						return item;
        	
        }


and inside the other method I have

new ItemFound(pistol, "No other items found in Bedroom", "You found Pistol", txt);


the error I get is:
cannot find symbol constructor ItemFound(boolean,java.lang.String,java.lang.String,javax.swing.JTextArea)

vchandra
Junior Poster in Training
73 posts since Mar 2010
Reputation Points: 13
Solved Threads: 14
 

Thanks guys I managed to figure it out. I just made a constructor and then a method and called the method.

FancyShoes
Newbie Poster
11 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You