0

I am working on an AEM site and I am trying to get the page property teaserImage I have the follow in my Java class, but when I do a build I get a cannot find symbol error.

public String getTeaserImg() {
    return this.getPageManager().getPage(url).getProperties().get("teaserImage").value;
}

But if I put a breakpoint on this similar function

public Page getPage() {
    return this.getPageManager().getPage(url);
}

And then execute this.getPageManager().getPage(url).getProperties().get("teaserImage").value in an Evulate expression window it gives me the property, so I'm not sure why on build it doesnt work when it works in this scenario.

enter image description here

jmona789
  • 2,711
  • 6
  • 24
  • 57
  • `getProperties` returns a `ValueMap`, which has the option to coerce properties to an expected type using `T get(String, Class)`. I would recommend using that. The `get` you’re calling is the default `Map.get` method that returns a plain `Object` (which you could cast to a string if you’re certain that’s what it is). Also, what you see in the debugger is the internal `value` property of a string, which gets you a `char` array. This isn’t normally available, even if you cast to `String`. So, in short, use `get("teaserImage", String.class)` to get the property value as a `String`. – Raphael Schweikert Dec 09 '21 at 18:41

1 Answers1

1

Cannot find symbol error means that the compiler cannot do this. Your code appears to be referring to something that the compiler doesn't understand.

What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?

In your example you are trying to get a property. If you can get that when you are debugging the code, that maybe means you forgot to add that property when you are trying to build the application.

hasankzl
  • 666
  • 4
  • 16
  • I'm not sure what you mean by "add that property when you are trying to build". Its a page property set in AEM – jmona789 Dec 09 '21 at 17:26