mm1985
mm1985

Reputation: 231

eclipse - type cannot be resolved

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

Answers (5)

Renato Lochetti
Renato Lochetti

Reputation: 4568

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

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

Upvotes: 1

Kumar Vivek Mitra
Kumar Vivek Mitra

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

Nikola Davidovic
Nikola Davidovic

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

Daniel Pereira
Daniel Pereira

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

kosa
kosa

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

Related Questions