I am trying to create an android app that involves pressing a button that takes a picture. My code is clean without any warnings or errors but when I run it on the emulator, and as soon as I press the photo button in the app, it says that your app has stopped.When I check the log file for the explanation it gives me the following
Any help would be appreciated. Thank you in advance.
07-27 20:44:11.676: E/AndroidRuntime(453): FATAL EXCEPTION: main
07-27 20:44:11.676: E/AndroidRuntime(453): java.lang.IllegalStateException: Could not find a method dispatchTakePhotoIntent(View) in the activity class com.example.mydressingroom.MainActivity for onClick handler on view class android.widget.Button
07-27 20:44:11.676: E/AndroidRuntime(453): at android.view.View$1.onClick(View.java:3026)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.view.View.performClick(View.java:3480)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.view.View$PerformClick.run(View.java:13983)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.os.Handler.handleCallback(Handler.java:605)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.os.Handler.dispatchMessage(Handler.java:92)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.os.Looper.loop(Looper.java:137)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.app.ActivityThread.main(ActivityThread.java:4340)
07-27 20:44:11.676: E/AndroidRuntime(453): at java.lang.reflect.Method.invokeNative(Native Method)
07-27 20:44:11.676: E/AndroidRuntime(453): at java.lang.reflect.Method.invoke(Method.java:511)
07-27 20:44:11.676: E/AndroidRuntime(453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-27 20:44:11.676: E/AndroidRuntime(453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-27 20:44:11.676: E/AndroidRuntime(453): at dalvik.system.NativeStart.main(Native Method)
07-27 20:44:11.676: E/AndroidRuntime(453): Caused by: java.lang.NoSuchMethodException: dispatchTakePhotoIntent [class android.view.View]
07-27 20:44:11.676: E/AndroidRuntime(453): at java.lang.Class.getConstructorOrMethod(Class.java:460)
07-27 20:44:11.676: E/AndroidRuntime(453): at java.lang.Class.getMethod(Class.java:915)
07-27 20:44:11.676: E/AndroidRuntime(453): at android.view.View$1.onClick(View.java:3019)
07-27 20:44:11.676: E/AndroidRuntime(453): ... 11 more
Here is my code
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user clicks the Photo button */
public void dispatchTakePhotoIntent(int actionCode) {
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePhotoIntent, actionCode);
}
}