Reputation: 3
I'm reading Android Application Developement for Dummies and i'm at Chapter 9 where I'm writing a Task reminder app. I have a onListItemClick method, but Eclipse keeps giving errors....
package com.dummies.android.taskreminder;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.*;
public class ReminderListActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin" };
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
setListAdapter(adapter);
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
}
}
}
my error: my error
Eclipse says: "View cannot be resolved to a type" "Syntax erroe on token ..... expected" (5x) "void is an invalid type for the variable onListItemClick"
What did I do wrong?
Upvotes: 0
Views: 1296
Reputation: 72331
You are trying to override the onListItemClick
method inside the onCreate
method. You need to take that code outside the onCreate()
method.
Upvotes: 1
Reputation: 33248
try this
package com.dummies.android.taskreminder;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.*;
public class ReminderListActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reminder_list);
String[] items = new String[] { "Foo", "Bar", "Fizz", "Bin" };
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.reminder_row, R.id.text1, items);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
}
}
Upvotes: 3
Reputation: 10959
You have placed the onListItemClick
method inside the onCreate
method. Move it outside of that method.
You are probably also missing import statements.
Upvotes: 2