My Main Activity extends ListActivity and displays a List. I am using custom Listitems defined in a class named DefinitionAdapter. I also have a seperate class that implements OnClickListener.
In the class DefinitionAdapter I set the OnClickListener to the ListItems:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
...
v.setOnClickListener(new OnItemClickListener(position) );
return v;
}
My custom OnClickListener is supposed to start another activity.
public class OnItemClickListener implements OnClickListener extends Activity {
private int position;
public OnItemClickListener(int p) {
position = p;
}
@Override
public void onClick(View v) {
Intent intent = new Intent(this, ShowDefinition.class);
startActivity(intent);
}
}
I am not sure that I am doing that right. I added my new activity to the manifest, as well as the activity i extended the listener with:
<activity android:name="ShowDefinition" android:label="@string/app_name">
</activity>
<activity android:name="OnItemClickListener" android:label="@string/app_name">
</activity>
Nonetheless, if I click on an Item in my List, the application always breaks with a NullPointerException. I think I am using the intent wrong... any Ideas?
In regard to Nikita Beloglazov's comment:
It breaks when I create the Intent:
Intent intent = new Intent(this, ShowDefinition.class);
Here's the stacktrace:
05-23 22:56:46.629: ERROR/AndroidRuntime(258): Uncaught handler: thread ma