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 Data Persistence CRUD Operations with SQLite Creating New Data

Sai Prasanth Sadasivam
Sai Prasanth Sadasivam
546 Points

Exception: Could not find a method submit(View) in the activity class for onClick handler on view android.widget.Button

I am trying to replicate the Datapersistance methods as a separate project. I am trying to store the data on a button click event. So I created a button and also code similar to yours for onclick event as mentioned below <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/btnnext" android:layout_alignParentBottom="true" android:layout_toRightOf="@+id/fieldcount" android:layout_toEndOf="@+id/fieldcount" android:onClick="submit"/>

public void Submit()
{
    Fields.setVariable_field1name(mchangingfield.getText().toString());
    Fields.setVariable_field2email(mfieldcount.getText().toString());

    MiningDataSource dataSource = new MiningDataSource(this);
    dataSource.create(Fields);
}

When I click the button – my app throws exception and gets closed.

This is my exception “java.lang.IllegalStateException: Could not find a method submit(View) in the activity class for onClick handler on view class android.widget.Button with id 'btnnext'”