Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Activity Lifecycle The Project Creating the Adapter

Kyle Baker
Kyle Baker
8,211 Points

What's going on?

error is this

Error:(33, 24) error: ListAdapter is abstract; cannot be instantiated

and code is this

package kybacorps.com.golf;

import android.app.ListActivity; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.Layout; import android.view.View; import android.view.Menu; import android.view.MenuItem; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.ListView; import android.widget.TextView;

public class MainActivity extends ListActivity { private Hole[] mHoles = new Hole[18]; private ListAdapter mListAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    int strokes = 0;
    for(int i=0; i<mHoles.length; i++) {
        mHoles[i] = new Hole("Hole: " + (i +1), strokes);
    }

    mListAdapter = new ListAdapter(this, mHoles);
    setListAdapter(mListAdapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

only thing i could think of is that he did an empty activity and i did a blank one, but i dont really know how that would mess it up. please help

1 Answer

It looks like you accidentally imported the generic android.widget.ListAdapter (which is an interface not a class) instead of your own custom ListAdapter class implementation. If you change the import to your own ListAdapter you should be golden.

Kyle Baker
Kyle Baker
8,211 Points

Thanks David! I was golden after two additional bugs (int in a setText and didn't set listview special id). :)