Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Unfortunately, Agenda has stopped

Esse erro ocorreu na durante a Aula 4, ele compila e roda. Porém quando eu coloco para "salvar" ele aparece esse erro . FormularioActivity

package br.com.alura.agenda;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import br.com.alura.agenda.modelo.Aluno;

public class FormularioActivity extends AppCompatActivity {

    private FormularioHelper helper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_formulario);
    }

    @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.menuFormularioOK:

                Aluno aluno = helper.pegaAluno();
                Toast.makeText(FormularioActivity.this, "Aluno " + aluno.getNome() + " salvo!", Toast.LENGTH_SHORT).show();

                finish();
                break;
    }
        return super.onOptionsItemSelected(item);
    }
}

ListaAlunosActivity

package br.com.alura.agenda;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class ListaAlunosActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lista_alunos);

        String[] alunos = { "Daniel", "Ronaldo", "Jeferson", "Felipe", "Daniel", "Ronaldo", "Jeferson", "Felipe"};
        ListView listaAluno = (ListView) findViewById(R.id.lista_alunos);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, alunos);
        listaAluno.setAdapter(adapter);

        Button novoAluno = (Button) findViewById(R.id.novoAluno);
        novoAluno.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentVaiProFormulario = new Intent(ListaAlunosActivity.this, FormularioActivity.class);
                startActivity(intentVaiProFormulario);
            }
        });
    }
}

activity_formulario

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

                <EditText android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Nome"
                    android:id="@+id/formularioNome"/>

                <EditText android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Endereço"
                    android:id="@+id/formularioEndereco"/>

                <EditText android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Telefone"
                    android:id="@+id/formularioTelefone"/>

                <EditText android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Site"
                    android:id="@+id/formularioSite"/>

                <RatingBar
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:max="10"
                    android:numStars="5"
                    android:id="@+id/formularioNota"/>

        </LinearLayout>

</ScrollView>

activity_lista_alunos

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/lista_alunos"/>

    <Button
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:text="+"
        android:textColor="#ffff"
        android:textSize="40sp"
        android:elevation="6dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:background="@drawable/fundo"
        android:stateListAnimator="@null"
        android:id="@+id/novoAluno"/>

</RelativeLayout>

Aluno

package br.com.alura.agenda.modelo;

/**
 * Created by Henrique on 17/02/2017.
 */
public class Aluno {
    private Long id;
    private String nome;
    private String endereco;
    private String telefone;
    private String site;
    private Double nota;

    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;
    }
}

FormularioHelper

package br.com.alura.agenda;

import android.widget.EditText;
import android.widget.RatingBar;

import br.com.alura.agenda.modelo.Aluno;

/**
 * Created by Henrique on 17/02/2017.
 */

public class FormularioHelper {


    private final EditText campoNome;
    private final EditText campoEndereco;
    private final EditText campoTelefone;
    private final EditText campoSite;
    private final RatingBar campoNota;

    public FormularioHelper(FormularioActivity activity){
         campoNome = (EditText) activity.findViewById(R.id.formularioNome);
         campoEndereco = (EditText) activity.findViewById(R.id.formularioEndereco);
         campoTelefone = (EditText) activity.findViewById(R.id.formularioTelefone);
         campoSite = (EditText) activity.findViewById(R.id.formularioSite);
         campoNota = (RatingBar) activity.findViewById(R.id.formularioNota);
    }

    public Aluno pegaAluno() {

        Aluno aluno = new Aluno ();

        aluno.setNome(campoNome.getText().toString());
        aluno.setEndereco(campoEndereco.getText().toString());
        aluno.setTelefone(campoTelefone.getText().toString());
        aluno.setSite(campoSite.getText().toString());
        aluno.setNota(Double.valueOf(campoNota.getProgress()));

        return aluno;
    }
}

ERROS:

E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: br.com.alura.agenda, PID: 923
                  java.lang.NullPointerException
                      at br.com.alura.agenda.FormularioActivity.onOptionsItemSelected(FormularioActivity.java:40)
                      at android.app.Activity.onMenuItemSelected(Activity.java:2600)
                      at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
                      at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
                      at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:113)
                      at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:675)
                      at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
                      at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
                      at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969)
                      at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:959)
                      at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:623)
                      at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:154)
                      at android.view.View.performClick(View.java:4438)
                      at android.view.View$PerformClick.run(View.java:18422)
                      at android.os.Handler.handleCallback(Handler.java:733)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:136)
                      at android.app.ActivityThread.main(ActivityThread.java:5017)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:515)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                      at dalvik.system.NativeStart.main(Native Method)
3 respostas

Henrique, posta o erro também

solução!

Vânia aqui esta o erro:

E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: br.com.alura.agenda, PID: 923
                  java.lang.NullPointerException
                      at br.com.alura.agenda.FormularioActivity.onOptionsItemSelected(FormularioActivity.java:40)
                      at android.app.Activity.onMenuItemSelected(Activity.java:2600)
                      at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:408)
                      at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:195)
                      at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:113)
                      at android.support.v7.app.AppCompatDelegateImplV9.onMenuItemSelected(AppCompatDelegateImplV9.java:675)
                      at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:822)
                      at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:156)
                      at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:969)
                      at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:959)
                      at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:623)
                      at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:154)
                      at android.view.View.performClick(View.java:4438)
                      at android.view.View$PerformClick.run(View.java:18422)
                      at android.os.Handler.handleCallback(Handler.java:733)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:136)
                      at android.app.ActivityThread.main(ActivityThread.java:5017)
                      at java.lang.reflect.Method.invokeNative(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:515)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                      at dalvik.system.NativeStart.main(Native Method)

Henrique,

faltou você inicializar o objeto "helper" no método onCreate do FormularioActivity da seguinte forma:

private FormularioHelper helper;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_formulario);

    //ALTERAÇÂO AQUI.....
    helper = new FormularioHelper(this);
}