• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Small Java Problem

CrackaLackaZe

Senior member
Whenever I try to compile the attached code, it gives me:

test2.java:45: non-static method getValue() cannot be referenced from a static context
numberz.setValue(numberz.getValue() + x);
^
test2.java:45: non-static method getValue() cannot be referenced from a static context
numberz.setValue(numberz.getValue() + x);
^
2 errors

Can anyone tell me why I'm getting that?
 
classname.methodname() is used to call static methods. to call non-static methods, call it without the "classname." part or use "this." instead of "classname."

so change numberz.setValue(numberz.getValue() + x); to

setValue(getValue() + x); OR this.setValue(this.getValue() + x); (both are equivalent)
 
Back
Top