“Variable Name” Cannot be Resolved to a Variable (Solved) in Java Programming

Java variable

When I learn Java Programming online, I have message “Variable Name” Cannot be Resolved to a Variable. I checked my code with my teacher code. It is exactly the same. But I have this error message.

But I try to finish the code, and the error message is disappear by itself… :)

The code is consisted of 2 classes: objectIntro and objectIntroTest. The problem code is in the waterAmount variable. But I keep finish the program, and the error message is disappeared.

package tes2;

public class objectIntro {
int tWater = 0;
public objectIntro() {


public objectIntro(int waterAmount) {
tWater = waterAmount;
public void addWater(int amount) {
tWater = tWater + amount ;

public void drinkWater(int amount) {
tWater = tWater - amount;


public int getWater() {
return tWater;


Ini adalah Class yang kedua untuk mentesnya:

package tes2;

public class objectIntroTest {

public static void main(String[] args) {
String x = "Hello";
objectIntro waterBottle = new objectIntro(0);
System.out.println("The remaining of water is " + waterBottle.getWater()) ;





Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )

Connecting to %s

%d blogger menyukai ini: