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
Epic117
  • 9
  • 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. – Araymer Jan 09 '16 at 22:57
  • Why does the parameter have the final modifier? – Jonathan Kittell Jan 09 '16 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](http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean) might help. – Ivo Mori Jan 10 '16 at 00:07

2 Answers2

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);
Mohammed Aouf Zouag
  • 17,042
  • 4
  • 41
  • 67
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));

Kayaman
  • 72,141
  • 5
  • 83
  • 121
  • Edited reply, if its any help the method uses inputs from another class – Epic117 Jan 09 '16 at 23:04
  • 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? – Kayaman Jan 10 '16 at 07:32
  • 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! – Epic117 Jan 10 '16 at 18:12