Pessoal boa tarde,
No exercício 3 da aula 2, após tentar salvar o formulário com a foto, aparece a mensagem "Agenda parou".
Alguém pode me ajudar?
Segue o logcat
03-22 15:36:48.975 16931-16931/? V/Zygote: Switching descriptor 10 to /dev/null
03-22 15:36:48.975 16931-16931/? D/dalvikvm: Late-enabling CheckJNI
03-22 15:36:48.975 16931-16931/? D/dalvikvm: Try to disable coredump for pid 16931
03-22 15:36:48.975 16931-16931/? D/dalvikvm: Process 16931 nice name: br.com.alura.agenda
03-22 15:36:48.975 16931-16931/? D/dalvikvm: Extra Options: not specified
03-22 15:36:49.395 16931-16931/br.com.alura.agenda W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
03-22 15:36:49.395 16931-16931/br.com.alura.agenda I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
03-22 15:36:49.395 16931-16931/br.com.alura.agenda W/dalvikvm: VFY: unable to resolve interface method 14533: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
03-22 15:36:49.395 16931-16931/br.com.alura.agenda D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
03-22 15:36:49.395 16931-16931/br.com.alura.agenda I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
03-22 15:36:49.395 16931-16931/br.com.alura.agenda W/dalvikvm: VFY: unable to resolve interface method 14537: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
03-22 15:36:49.395 16931-16931/br.com.alura.agenda D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
03-22 15:36:49.425 16931-16931/br.com.alura.agenda I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
03-22 15:36:49.425 16931-16931/br.com.alura.agenda W/dalvikvm: VFY: unable to resolve virtual method 412: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
03-22 15:36:49.425 16931-16931/br.com.alura.agenda D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-22 15:36:49.425 16931-16931/br.com.alura.agenda I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
03-22 15:36:49.425 16931-16931/br.com.alura.agenda W/dalvikvm: VFY: unable to resolve virtual method 434: Landroid/content/res/TypedArray;.getType (I)I
03-22 15:36:49.425 16931-16931/br.com.alura.agenda D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
03-22 15:36:49.515 16931-16931/br.com.alura.agenda E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 43
03-22 15:36:49.525 16931-16931/br.com.alura.agenda E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 46
03-22 15:36:49.525 16931-16931/br.com.alura.agenda E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 47
03-22 15:36:49.525 16931-16931/br.com.alura.agenda E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 47
03-22 15:36:49.525 16931-16931/br.com.alura.agenda E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 47
03-22 15:36:49.525 16931-16931/br.com.alura.agenda E/IMGSRV: :0: PVRDRMOpen: TP3, ret = 48
03-22 15:36:49.545 16931-16931/br.com.alura.agenda D/OpenGLRenderer: Enabling debug mode 0'
FormulárioHelper:
public class FormularioHelper {
private final EditText campoNome;
private final EditText campoEndereco;
private final EditText campoTelefone;
private final EditText campoSite;
private final RatingBar campoNota;
private final ImageView foto;
private Aluno aluno;
public FormularioHelper(FormularioActivity activity) {
campoNome = (EditText) activity.findViewById(R.id.formulario_nome);
campoEndereco = (EditText) activity.findViewById(R.id.formulario_endereco);
campoTelefone = (EditText) activity.findViewById(R.id.formulario_telefone);
campoSite = (EditText) activity.findViewById(R.id.formulario_site);
campoNota = (RatingBar) activity.findViewById(R.id.formulario_nota);
foto = (ImageView) activity.findViewById(R.id.foto);
aluno = new Aluno();
}
public Aluno pegaAluno() {
aluno.setNome(campoNome.getText().toString());
aluno.setEndereco(campoEndereco.getText().toString());
aluno.setSite(campoSite.getText().toString());
aluno.setTelefone(campoTelefone.getText().toString());
aluno.setNota(Double.valueOf(campoNota.getProgress()));
return aluno;
}
public void preencheFormulario(Aluno aluno) {
campoNome.setText(aluno.getNome());
campoEndereco.setText(aluno.getEndereco());
campoTelefone.setText(aluno.getTelefone());
campoSite.setText(aluno.getSite());
campoNota.setProgress(aluno.getNota().intValue());
if(aluno.getFoto() != null) {
carregaImagem(aluno.getFoto());
}
this.aluno = aluno;
}
public ImageView getFoto() {
return foto;
}
public void carregaImagem(String localArquivoFoto) {
Bitmap imagemFoto = BitmapFactory.decodeFile(localArquivoFoto);
Bitmap imagemFotoReduzida = Bitmap.createScaledBitmap(imagemFoto, 100, 100, true);
aluno.setFoto(localArquivoFoto);
foto.setImageBitmap(imagemFotoReduzida);
}
}
AlunoDAO:
public class AlunoDAO extends SQLiteOpenHelper {
public AlunoDAO(Context context) {
super(context, "Agenda", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "CREATE TABLE Alunos(" +
"id INTEGER PRIMARY KEY," +
"nome TEXT NOT NULL," +
"endereco TEXT," +
"telefone TEXT," +
"site TEXT," +
"nota REAL);";
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
String sql = "DROP TABLE IF EXISTS Alunos";
db.execSQL(sql);
onCreate(db);
}
public void insere(Aluno aluno) {
SQLiteDatabase db = getWritableDatabase();
ContentValues dados = pegaDadosDoAluno(aluno);
db.insert("Alunos ", null, dados);
}
public void altera(Aluno aluno) {
SQLiteDatabase db = getWritableDatabase();
ContentValues dados = pegaDadosDoAluno(aluno);
String[] params = {aluno.getId().toString()};
db.update("Alunos", dados, "id = ?", params);
}
public List<Aluno> buscaAlunos() {
String sql = "SELECT * FROM Alunos";
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery(sql, null);
List<Aluno> alunos = new ArrayList<>();
while(c.moveToNext()) {
Aluno aluno = new Aluno();
aluno.setId(c.getLong(c.getColumnIndex("id")));
aluno.setNome(c.getString(c.getColumnIndex("nome")));
aluno.setEndereco(c.getString(c.getColumnIndex("endereco")));
aluno.setTelefone(c.getString(c.getColumnIndex("telefone")));
aluno.setSite(c.getString(c.getColumnIndex("site")));
aluno.setNota(c.getDouble(c.getColumnIndex("nota")));
alunos.add(aluno);
}
c.close();
return alunos;
}
public void deleta(Aluno aluno) {
SQLiteDatabase db = getWritableDatabase();
String[] params = {aluno.getId().toString()};
db.delete("Alunos", "id = ?", params);
}
@NonNull
private ContentValues pegaDadosDoAluno(Aluno aluno) {
ContentValues dados = new ContentValues();
dados.put("nome", aluno.getNome());
dados.put("endereco", aluno.getEndereco());
dados.put("telefone", aluno.getTelefone());
dados.put("site", aluno.getSite());
dados.put("nota", aluno.getNota());
dados.put("caminhoFoto", aluno.getFoto());
return dados;
}
}
FormularioActivity:
public class FormularioActivity extends AppCompatActivity {
private FormularioHelper helper;
private String localArquivoFoto;
private static final int TIRA_FOTO = 123;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_formulario);
helper = new FormularioHelper(this);
Intent intent = getIntent();
Aluno aluno = (Aluno) intent.getSerializableExtra("aluno");
if(aluno != null) {
helper.preencheFormulario(aluno);
}
ImageView foto = helper.getFoto();
foto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
localArquivoFoto = getExternalFilesDir(null) + "/" + System.currentTimeMillis() + ".jpg";
File arquivo = new File(localArquivoFoto);
Uri localFoto = Uri.fromFile(new File(localArquivoFoto));
Intent irParaCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
irParaCamera.putExtra(MediaStore.EXTRA_OUTPUT, localFoto);
startActivityForResult(irParaCamera, TIRA_FOTO);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_formulario, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.menu_formulario_ok:
Aluno aluno = helper.pegaAluno();
AlunoDAO dao = new AlunoDAO(this);
if(aluno.getId() != null) {
dao.altera(aluno);
} else {
dao.insere(aluno);
}
dao.close();
Toast.makeText(FormularioActivity.this, "Aluno " + aluno.getNome() + " salvo!",
Toast.LENGTH_SHORT).show();
finish();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == TIRA_FOTO) {
if(resultCode == Activity.RESULT_OK) {
helper.carregaImagem(this.localArquivoFoto);
} else {
this.localArquivoFoto = null;
}
}
}
}
Aluno:
public class Aluno implements Serializable {
private Long id;
private String nome;
private String endereco;
private String telefone;
private String site;
private Double nota;
private String foto;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getEndereco() {
return endereco;
}
public void setEndereco(String endereco) {
this.endereco = endereco;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getSite() {
return site;
}
public void setSite(String site) {
this.site = site;
}
public Double getNota() {
return nota;
}
public void setNota(Double nota) {
this.nota = nota;
}
@Override
public String toString() {
return getId() + " - " + getNome();
}
public String getFoto() {
return foto;
}
public void setFoto(String foto) {
this.foto = foto;
}
}
Somente uma observação: Não estou utilizando emulador, estou testando direto no smartphone.
Desde já obrigado,