0

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

5 Answers 5

1

You need to add "type" variable to your class.

Example:

public class Restaurant {   
    private String name="";     
    private String address="";   
    private String type="";
    ............
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Solved the problem.
1

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; } }

Comments

1

You dont have an attribute named type of type String, like:

public class Restaurant {
    private String type;
   ...
}

Comments

0

The attribute type, used in getType and setType, is not declared. You need to do it in order to get it working.

Comments

0

- You have not declared type as a field in the class scope, thats why u are getting this error

For eg:

private String type;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.