Reputation: 231
I am following the tutorial from the book "Android Programming Tutorials, 3rd Edition".
In lesson number 3 "A Fancier Form" I experience some problems within Eclipse.
The author says to add the following line of code:
public String getType(){ return(type); } public void setType(String type) { this.type=type;
Which results in having the following code:
package apt.tutorial;
public class Restaurant {
private String name="";
private String address="";
public String getName() { return(name); }
public void setName(String name) { this.name=name; }
public String getAddress() { return(address); }
public void setAddress(String address) { this.address=address; }
public String getType(){ return(type); }
public void setType(String type) { this.type=type; }
}
eclipse gives me the following errors: For the first "Type" I get type cannot be resolved to a variable. For the second "Type" I get type cannot be resolved or is not a field.
I hope someone can explain me which steps to take to fix this.
Thanks in advance
Upvotes: 0
Views: 4177
Reputation: 4568
You dont have an attribute named type
of type String
, like:
public class Restaurant {
private String type;
...
}
Upvotes: 1
Reputation: 33534
- You have not declared type
as a field in the class scope, thats why u are getting this error
For eg:
private String type;
Upvotes: 0
Reputation: 8656
You are missing a field type:
package apt.tutorial;
public class Restaurant { private String type= ""; private String name=""; private String address=""; public String getName() { return(name); } public void setName(String name) { this.name=name; } public String getAddress() { return(address); } public void setAddress(String address) { this.address=address; } public String getType(){ return(type); } public void setType(String type) { this.type=type; } }
Upvotes: 1
Reputation: 2785
The attribute type, used in getType and setType, is not declared. You need to do it in order to get it working.
Upvotes: 0
Reputation: 66637
You need to add "type" variable to your class.
Example:
public class Restaurant {
private String name="";
private String address="";
private String type="";
............
}
Upvotes: 1