Código
public class primeiraTela extends AppCompatActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_primeira_tela);
Button botaocan = findViewById(R.id.botaoCanid);
botaocan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
if (requestCode == 0) {
if (resultCode == Activity.RESULT_OK) {
Intent fotoinfo = new Intent(this, fotocomInfo.class);
startActivity(fotoinfo);
} else {
}
}
}
}
Erro:
E/AndroidRuntime: FATAL EXCEPTION: main Process: believe.com.br.believeundb, PID: 4189 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { act=inline-data (has extras) }} to activity {believe.com.br.believeundb/believe.com.br.believeundb.primeiraTela}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference at android.app.ActivityThread.deliverResults(ActivityThread.java:4094) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4137) at android.app.ActivityThread.-wrap20(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1529) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6123) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference at believe.com.br.believeundb.primeiraTela.onActivityResult(primeiraTela.java:41) at android.app.Activity.dispatchActivityResult(Activity.java:6931) at android.app.ActivityThread.deliverResults(ActivityThread.java:4090)