1
Code
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 {
}
}
}
}
Error:
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)