Generate Getters and Setters (in Eclipse): "the operation is not applicable to the current selection"

Generate Getters and Setters (in Eclipse): “the operation is not applicable to the current selection”

I don’t get why it doesn’t let me generate getters and setters

This would be a question you should ask the Eclipse community, but be sure to include which language you’re writing in, and perhaps a snippet of the code you’re trying to generate getters/setters for.

I had that error and I was able to resolve it by creating an object and using the variables.

for example, I created the following Student.java but I was not able to generate getters and setters for these.

package hello;
public class Student {

	int age;
	int id;
	String  name;
	}

Once I created the following code (HelloWorld.java), I was able to go back to Student.java and generate getters and setters.

package hello;
public class HelloWorld {
public static void main(String[] args) {

Student A= new Student();
A.setAge(15);
A.setId(1); 
A.setName("Alpha");
System.out.println(A.getName() + " is "+ A.getAge() + " years old.");

}
}

Hope that helped.

I ran into similar issue. What worked for me is having my cursor pointed inside the class curley’s when I right clicked and selected source-> Generate Getters and Setters. It’s weird though.

1 Like