I just have a button in my activity_main.xml view as below:
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/capt_sig" android:onClick="openCaptureActivity" //click event here android:text="@string/capture_signature" android:layout_below="@+id/result" android:layout_alignParentEnd="true" android:layout_marginTop="235dp" android:clickable="true" android:typeface="sans" /> and have below onclick event written in MainActivity.java
public void openCaptureActivity(View view){ setContentView(R.layout.activity_capture_signature); } Now onClick of the button it opens below activity with name activity_capture_signature.xml and here are the contents.
<android.gesture.GestureOverlayView android:id="@+id/signaturePad" android:layout_width="match_parent" android:layout_height="100dp" android:layout_weight="5" android:background="#FFF" android:eventsInterceptionEnabled="true" android:fadeEnabled="false" android:gestureColor="#000" android:gestureStrokeLengthThreshold="0.1" android:gestureStrokeType="multiple" android:orientation="horizontal"> </android.gesture.GestureOverlayView> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/saveSig" android:layout_marginTop="100dp" android:onClick="SaveSignature" //click event here android:text="Capture"/> I have added a onClick for button as well here as you can see and the event is written in CaptureSignatureActivity.java as below:
public void SaveSignature(View v){ //Do some stuff } Even with this setups, the SaveSignature event throws FATAL EXCEPTION as below:
java.lang.IllegalStateException: Could not find method SaveSignature(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.support.v7.widget.AppCompatButton with id 'saveSig'
I am still not able understand that even after adding click event in activity, why this exception is occurring. Is this because of the way I open the activity from parent? Is there anything am missing here?