Este código não funciona na aplicação.
Button botaoFoto = (Button) findViewById(R.id.formulario_botao_foto);
botaoFoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File arquivoFoto = new File("/foto.jpg");
intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(arquivoFoto));
startActivity(intentCamera);
}
});
Abre no emulador e quando clica no botão + para ir para o formulário da o seguinte erro "Unfortunately, agenda has stopped." e fecha a aplicação. Já tentei nas versões 7, 6, 5, e ocorre em todas.
[ 11-27 11:12:39.086 3849: 3849 W/ ]
Unrecognized GLES max version string in extensions: GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_OES_packed_depth_stencil GL_OES_vertex_half_float GL_OES_texture_npot GL_OES_rgb8_rgba8 ANDROID_EMU_CHECKSUM_HELPER_v1
[ 11-27 11:12:39.086 3849: 3849 W/ ]
Process pipe failed
D/Atlas: Validating map...
I/OpenGLRenderer: Initialized EGL, version 1.4
D/EGL_emulation: eglCreateContext: 0x7f59c9938a20: maj 2 min 0 rcv 2
D/EGL_emulation: eglMakeCurrent: 0x7f59c9938a20: ver 2 0
D/OpenGLRenderer: Enabling debug mode 0
E/EGL_emulation: tid 3871: eglSurfaceAttrib(1199): error 0x3009 (EGL_BAD_MATCH)
W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7f59c986a140, error=EGL_BAD_MATCH
D/EGL_emulation: eglMakeCurrent: 0x7f59c9938a20: ver 2 0
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.makrosys.agenda, PID: 3849
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.makrosys.agenda/br.com.makrosys.agenda.FormularioActivity}: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageView cannot be cast to android.widget.Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatImageView cannot be cast to android.widget.Button
at br.com.makrosys.agenda.FormularioActivity.onCreate(FormularioActivity.java:41)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)