8
respostas

emulador nao roda o aplicativo

nao consigo rodar no emulador (Genymotion) ele abre e fecha,preciso de ajuda para revisar os codigos. Obrigado por quem se interessar por me ajudar :3

lista_aluno.java


package br.com.alura.listaaluno;

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;

import java.util.List;

import br.com.alura.listaaluno.dao.AlunoDAO;
import br.com.alura.listaaluno.modelo.Aluno;


public class lista_alunoActivity extends AppCompatActivity {

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

        AlunoDAO dao=new AlunoDAO(this);
        List<Aluno> alunos= dao.buscaAlunos();
        dao.close();

        ListView listaAluno=(ListView) findViewById(R.id.lista);
        ArrayAdapter<Aluno>  adapter=new ArrayAdapter<Aluno>(this,android.R.layout.simple_list_item_1,alunos );
        listaAluno.setAdapter(adapter);

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


    }
}
8 respostas
lista aluno.xml


<?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="match_parent"
        android:id="@+id/lista"
        />
    <Button
        android:text="+"
        android:textColor="#ffffff"
        android:textSize="40sp"
        android:layout_width="56dp"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"
        android:background="@drawable/fundo"
        android:id="@+id/novo"

        />
</RelativeLayout>
formularioHelper.java

package br.com.alura.listaaluno;

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

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

public class FormularioHelper {

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

    public FormularioHelper(Formulario activity){

        campoNome=(EditText)activity.findViewById(R.id.nome);
         campoNumero=(EditText) activity.findViewById(R.id.numero);
         campoEndereco=(EditText) activity.findViewById(R.id.endereco);
         campoSite=(EditText) activity.findViewById(R.id.site);
         campoNota=(RatingBar) activity.findViewById(R.id.nota);



    }


    public Aluno pegaAluno() {

        Aluno aluno=new Aluno();
        aluno.setNome(campoNome.getText().toString());
        aluno.setNumero(campoNumero.getText().toString());
        aluno.setEndereco(campoEndereco.getText().toString());
        aluno.setSite(campoSite.getText().toString());
        aluno.setNota(Double.valueOf(campoNota.getProgress()));



        return aluno;
    }
}
aluno.java

package br.com.alura.listaaluno.modelo;

public class Aluno {
    private Long id;
    private String nome;
    private String numero;
    private String endereco;
    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 getNumero() {
        return numero;
    }

    public void setNumero(String numero) {
        this.numero = numero;
    }

    public String getEndereco() {
        return endereco;
    }

    public void setEndereco(String endereco) {
        this.endereco = endereco;
    }

    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;
    }
}
alunoDAO.java

package br.com.alura.listaaluno.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.util.ArrayList;
import java.util.List;

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

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,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) {
        final SQLiteDatabase db = getWritableDatabase();
        ContentValues dados= new ContentValues();
        dados.put("nome",aluno.getNome());
        dados.put("numero",aluno.getNumero());
        dados.put("endereco",aluno.getEndereco());
        dados.put("site",aluno.getSite());
        dados.put("nota",aluno.getNota());
        db.insert("Alunos",null,dados);
    }

    public List<Aluno> buscaAlunos() {

        String sql = "SELECT * FROM Alunos;";

        SQLiteDatabase db=getReadableDatabase();
         Cursor c= db.rawQuery(sql,null);
         List<Aluno> alunos=new ArrayList<Aluno>();
         while (c.moveToNext()){
         Aluno aluno=new Aluno();
         aluno.setId(c.getLong(c.getColumnIndex("id")));
         aluno.setNome( c.getString(c.getColumnIndex("nome")));
         aluno.setNumero(c.getString(c.getColumnIndex("numero")));
         aluno.setEndereco(c.getString(c.getColumnIndex("endereco")));
         aluno.setSite(c.getString(c.getColumnIndex("site")));
         aluno.setNota(c.getDouble(c.getColumnIndex("nota")));
         alunos.add(aluno);


    }
       c.close();

        return alunos;}

}
Formulario.java

package br.com.alura.listaaluno;

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.Switch;
import android.widget.Toast;

import br.com.alura.listaaluno.dao.AlunoDAO;
import br.com.alura.listaaluno.modelo.Aluno;


public class Formulario extends AppCompatActivity {

    private FormularioHelper helper;

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

        helper=new FormularioHelper(this);



    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu){

       new MenuInflater(getApplication()).inflate(R.layout.menu, 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);
                dao.insere(aluno);
                dao.close();


            Toast.makeText(Formulario.this, "aluno"+aluno.getNome()+"salvo!",Toast.LENGTH_SHORT).show();

            finish() ;
            break;
        }


        return super.onOptionsItemSelected(item);

    }

}
Activity_formulario.xml

<?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:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
>
    <EditText

        android:hint="nome"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/nome"
    />
    <EditText
        android:hint="numero"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/numero"
        />
    <EditText
        android:hint="endereco"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/endereco"
        />
    <EditText
        android:hint="site"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/site"
        />
    <RatingBar
        android:numStars="5"
        android:max="10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:id="@+id/nota"
        />


</LinearLayout>
</ScrollView>

menu eu tive que fazer , e por ultimo é o drawable nem vou postá-lo

menu.xml

<menu


    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:yourapp="http://schemas.android.com/apk/res/android"
    tools:context="br.com.alura.listaaluno.Formulario"
    android:layout_height="wrap_content"
    android:layout_width="match_parent">
    <item
        android:id="@+id/menu_formulario_ok"
        android:title="Ok"
        android:icon="@drawable/ic_confirmar"
        yourapp:showAsAction="ifRoom"

        />

</menu>

Fala ai, tranquilo ?

Cara qual é o erro que está dando? Fica mais fácil de te ajudar se soubermos.