Within my onCreate method:
add = (Button)findViewById(R.id.add);
add.setOnClickListener(new MyOnClickListener()); //null pointer here
public class MyOnClickListener implements OnClickListener
{
@Override
public void onClick(View v)
{
//send information to database
}
}
XML File
<Button
android:id="@+id/add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/hello"
android:layout_alignBottom="@+id/hello"
android:layout_alignRight="@+id/id"
android:layout_marginRight="72dp"
android:text="Add" />
I know there are two ways to do it one using the XML attribute and the other way is the one I chose using setOnClickListener. I read another post and it said to clean the project however I am still getting a null pointer exception. What is wrong?