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

Banco de Dados Android

Não estou conseguindo exibir na tela os nomes dos alunos que foram inseridos no formulário. o erro ocorre no momento que retorna para a janela onde será exibido o registro. Pilha de erro:

11-07 03:14:51.551    1006-1006/cadastro.caelum.curso.com.br.cadastrocaelum E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to resume activity {cadastro.caelum.curso.com.br.cadastrocaelum/cadastro.caelum.curso.com.br.cadastrocaelum.LisStudentActivity}: android.app.SuperNotCalledException: Activity {cadastro.caelum.curso.com.br.cadastrocaelum/cadastro.caelum.curso.com.br.cadastrocaelum.LisStudentActivity} did not call through to super.onRestart()
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.app.SuperNotCalledException: Activity {cadastro.caelum.curso.com.br.cadastrocaelum/cadastro.caelum.curso.com.br.cadastrocaelum.LisStudentActivity} did not call through to super.onRestart()
            at android.app.Activity.performRestart(Activity.java:5065)
            at android.app.Activity.performResume(Activity.java:5074)
            at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
            at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
11-07 03:14:55.631    1006-1006/cadastro.caelum.curso.com.br.cadastrocaelum I/Process﹕ Sending signal

A Activity onde exibe o registro

public class LisStudentActivity extends Activity {

    private ListView list;
    private ArrayAdapter<Student> adapter;

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

        this.list =(ListView)findViewById(R.id.lista_alunos);
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Toast.makeText(LisStudentActivity.this,
                "Clicou na posição: "+position,Toast.LENGTH_SHORT).show();
            }
        });

        list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) {

                Toast.makeText(LisStudentActivity.this,"Clique longo na posição: "+position+
                "\nNome: "+adapter.getItemAtPosition(position),Toast.LENGTH_LONG).show();

                /* Caso deseje consumir o evento*/
                return true;
            }
        });
    }

    @Override
    protected void onRestart() {
        StudentDAO studantDAO = new StudentDAO(LisStudentActivity.this);
        List<Student> student = studantDAO.select();
        studantDAO.close();

        int layout = android.R.layout.simple_list_item_1;
        adapter = new ArrayAdapter<Student>(LisStudentActivity.this,
        layout,student);
        list.setAdapter(adapter);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater menuInflater= getMenuInflater();
      menuInflater.inflate(R.menu.lista_alunos,menu);
      return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemClick = item.getItemId();
        switch (itemClick){
            case R.id.novo:
                Intent viewFormulario = new Intent(this,FormularioActivity.class);
                startActivity(viewFormulario);
                break;
            case 1:
                break;

        }
        return super.onOptionsItemSelected(item);
    }
}
3 respostas

O erro está pq vc esta usando o método onRestart para fazer a exibição de sua lista. Quando você retorna a tela o ciclo de vida termina no onResume. Tire esse código do onRestarte e coloque em onResume que funcionará certamente.

solução!

monta seu onCreate do teu dao assim:

@Override
    public void onCreate(SQLiteDatabase db) {

        String ddl = "CREATE TABLE Alunos(id INTEGER PRIMARY KEY AUTOINCREMENT, "
                + "nome TEXT UNIQUE NOT NULL, "
                + "telefone TEXT, "
                + "endereco TEXT, "
                + "site TEXT, "
                + "foto TEXT, "
                + "nota real); ";

        db.execSQL(ddl);

    }

Isso ai resolve o problema.

Brow deu certo aqui, valeu mesmo.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software