Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8558145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:44:34+00:00 2026-06-11T15:44:34+00:00

I was continuing work on my Android tutorial that my teacher gave to me.

  • 0

I was continuing work on my Android tutorial that my teacher gave to me. The idea of the program is to enter in a restaurant name, address and type of restaurant and create an interface that shows this.

I believe I copied the code exactly. However, I get an error:

"The method getType() is undefined for the type Restaurant".

I have no idea what that means and how to fix it.

The suggestion Eclipse gave me was to “Create method getType() in type restaurant” but when I do it I get a null pointer exception when running my program, entering the details of my restaurant and saving them.

So my questions are:

  • What does the error mean?
  • How do I fix it?

Below is my main class Lunchlist.java:

@SuppressLint({ "ParserError", "ParserError" }) 
public class LunchList extends Activity {
    List<Restaurant> model=new ArrayList<Restaurant>();
    ArrayAdapter<Restaurant> adapter=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lunch_list);

        Button save=(Button)findViewById(R.id.btnSave);

        save.setOnClickListener(onSave);

        ListView list=(ListView)findViewById(R.id.restaurants);

        adapter=new RestaurantAdapter();
        list.setAdapter(adapter);
    }

   private View.OnClickListener onSave=new View.OnClickListener() {
        public void onClick(View v){
            Restaurant r=new Restaurant();
            EditText name=(EditText) findViewById(R.id.name);
            EditText address=(EditText) findViewById(R.id.address);


            r.setName(name.getText().toString());
            r.setAddress(address.getText().toString());

            RadioGroup types=(RadioGroup)findViewById(R.id.types);

            switch (types.getCheckedRadioButtonId()){
            case R.id.sit_down:
                r.setType("sit_down");
                break;
            case R.id.take_out:
                r.setType("take_out");
                break;
            case R.id.delivery:
                r.setType("delivery");
                break;

            }
            adapter.add(r);
        }
        };

        class RestaurantAdapter extends ArrayAdapter<Restaurant> {
            RestaurantAdapter(){
                super(LunchList.this,R.layout.row,model);
            }
        public View getView(int position, View convertView, ViewGroup parent){
            View row=convertView;
            RestaurantHolder holder=null;

            if (row==null){
                LayoutInflater inflater=getLayoutInflater();

                row=inflater.inflate(R.layout.row, parent, false);
                holder=new RestaurantHolder(row);
                row.setTag(holder);
            }
            else{
                holder=(RestaurantHolder)row.getTag();
            }
            holder.populateFrom(model.get(position));
            return(row);
        }
        }

        static class RestaurantHolder {
            private TextView name=null;
            private TextView address=null;
            private ImageView icon=null;
            private View row=null;

            RestaurantHolder(View row){
                this.row=row;

                name=(TextView)row.findViewById(R.id.title);
                address=(TextView)row.findViewById(R.id.address);
                icon=(ImageView)row.findViewById(R.id.icon);
            }

            void populateFrom(Restaurant r){
                name.setText(r.getName());
                address.setText(r.getAddress());

            if (r.getType().equals("sit_down")){
                icon.setImageResource(R.drawable.sitdown);
            }
            else if (r.getType().equals("takeout")){
                icon.setImageResource(R.drawable.takeout);  
            }
            else{
                icon.setImageResource(R.drawable.delivery);
            }

        }
}
}

This class is Restaurant.java:

public class Restaurant {
private String name="";
private String address="";
private Object type;

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 void setType(String string) {
    // TODO Auto-generated method stub

}
public String toString(){
    return(getName());
}






}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:44:35+00:00Added an answer on June 11, 2026 at 3:44 pm

    Add this to your Restaurant class

    public String getType() {
        return type;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am continuing work on a project that I've been at for some time
I'm continuing to work out of an outdated bioinformatics book and I'm attempting to
Continuing adopting my code to work with IE... I have a hidden div containing
Continuing on my attempt to create a DateTime class , I am trying to
In my Android app, I need to talk to a webserver that expects marshalled
Suppose that, I have an android app that launches browser with some url supplied
We've got an android app and an iPhone app (same functionality) that use sqlite
I'm continuing work on a search term suggestion tool using Jquery UI. I am
I'm using Eclipse 3.7.0 to build my Android app. I saw the post that
I have a ListActivity in Android. Each row is just an item that starts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.