0

Excuse me for what might be a very obvious question, but I have literally spent the whole day working on a project and now I am stuck with a very simple issue, yet I cant seem to work it out. So I have this very simple method

public String method(final Node<Tag> child) { return child.getData().getAttributeValue(); } 

I believe it returns a single string, now my question is how can i get that return string and print it inside another method. In other words I want to print what this method returns. Thanks a lot for your time!

EDIT: I tried calling the method with the two options below and I had the following errors:

BrowserGui.java:185: error: cannot find symbol String foo = method(childNode); ^ symbol: variable childNode

and by simply calling it this occured:

BrowserGui.java:195: error: cannot find symbol System.out.print(child.getData().getAttributeValue()); ^ symbol: variable child location: class BrowserGui.TextClickListener 1 error 
3
  • In whatever method you're calling this one, assign it to a string. So String x = method(parameter); Now it's in your x string and you can do whatever with it. If you only need to print it, you can put the function call directly in a println statement. Commented Jan 9, 2016 at 22:57
  • Why does the parameter have the final modifier? Commented Jan 9, 2016 at 22:58
  • From the cannot find symbol it's clear that is a compile time error. This What does a cannot find symbol compilation error mean might help. Commented Jan 10, 2016 at 0:07

2 Answers 2

1

Simply call sysout on it:

System.out.println(child.getData().getAttributeValue()); 

It's equivalent to

String value = child.getData().getAttributeValue(); System.out.println(value); 
Sign up to request clarification or add additional context in comments.

Comments

1

Either assign the return value to a variable and print it

String foo = method(childNode); System.out.println(foo); 

or just display the return value directly with System.out.println(method(childNode));

3 Comments

Edited reply, if its any help the method uses inputs from another class
Well obviously you have to use the correct variable names. The childNode is just an example based on your code. You're one of those people who skip basic tutorials because they're too boring, aren't you?
no its just that im working on a group project and I got lost inside all of the other persons code, to a state of not even knowing how to call one simple return value, either way I managed to get the string by creating a new object and giving it a pseudo value, thanks for your time!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.