0
I am with an application that I am running directly on Android phone, and it generates an error message on Logcat
12-05 15:55:18.043: D/ActivityThread(27221): setTargetHeapUtilization:0.25
12-05 15:55:18.043: D/ActivityThread(27221): setTargetHeapIdealFree:8388608
12-05 15:55:18.043: D/ActivityThread(27221): setTargetHeapConcurrentStart:2097152
12-05 15:55:18.173: E/SQLiteLog(27221): (1) no such table: carro
12-05 15:55:18.173: E/livro(27221): Erro ao buscar os carros: android.database.sqlite.SQLiteException: no such table: carro (code 1): , while compiling: SELECT _id, nome, placa, ano FROM carro
12-05 15:55:18.173: D/AndroidRuntime(27221): Shutting down VM
12-05 15:55:18.173: W/dalvikvm(27221): threadid=1: thread exiting with uncaught exception (group=0x40f10438)
12-05 15:55:18.183: E/AndroidRuntime(27221): FATAL EXCEPTION: main
12-05 15:55:18.183: E/AndroidRuntime(27221): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bancodedados/com.example.bancodedados.CadastroCarros}: java.lang.NullPointerException
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.ActivityThread.access$700(ActivityThread.java:143)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.os.Looper.loop(Looper.java:137)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.ActivityThread.main(ActivityThread.java:4960)
12-05 15:55:18.183: E/AndroidRuntime(27221): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 15:55:18.183: E/AndroidRuntime(27221): at java.lang.reflect.Method.invoke(Method.java:511)
12-05 15:55:18.183: E/AndroidRuntime(27221): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
12-05 15:55:18.183: E/AndroidRuntime(27221): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
12-05 15:55:18.183: E/AndroidRuntime(27221): at dalvik.system.NativeStart.main(Native Method)
12-05 15:55:18.183: E/AndroidRuntime(27221): Caused by: java.lang.NullPointerException
12-05 15:55:18.183: E/AndroidRuntime(27221): at com.example.bancodedados.RepositorioCarro.listarCarros(RepositorioCarro.java:155)
12-05 15:55:18.183: E/AndroidRuntime(27221): at com.example.bancodedados.CadastroCarros.atualizarLista(CadastroCarros.java:36)
12-05 15:55:18.183: E/AndroidRuntime(27221): at com.example.bancodedados.CadastroCarros.onCreate(CadastroCarros.java:30)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.Activity.performCreate(Activity.java:5203)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
12-05 15:55:18.183: E/AndroidRuntime(27221): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
12-05 15:55:18.183: E/AndroidRuntime(27221): ... 11 more
12-05 15:55:31.523: I/Process(27221): Sending signal. PID: 27221 SIG: 9
12-05 15:56:27.283: I/Process(27836): Sending signal. PID: 27836 SIG: 9
the message that appears on the phone is that Bando de Dados Parou
my class Registration
package com.example.bancodedados;
import java.util.List;
import com.example.bancodedados.model.Carro;
import com.example.bancodedados.model.Carro.Carros;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
public class CadastroCarros extends ListActivity {
protected static final int INSERIR_EDITAR = 1;
protected static final int BUSCAR = 2;
public static RepositorioCarro repositorio;
private List<Carro> carros;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
repositorio = new RepositorioCarro(this);
atualizarLista();
}
protected void atualizarLista() {
// Pega a lista de carros e exibe na tela
carros = repositorio.listarCarros();
//Adaptador de lista customizado para cada linha de um carro
// Fonte está na biblioteca LivroAndroidCap14-BancoDados-Library
setListAdapter(new CarroListAdapter(this, carros));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
//getMenuInflater().inflate(R.menu.menu_cadastro_carros, menu);
menu.add(0, INSERIR_EDITAR, 0, "Inserir Novo").setIcon(R.drawable.novo);
menu.add(0, BUSCAR, 0, "Buscar").setIcon(R.drawable.pesquisar);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// Clicou no menu
switch (item.getItemId()) {
case R.id.menu_editar:
// Abre a tela com o formulário para adicionar
startActivityForResult(new Intent(this, EditarCarro.class), INSERIR_EDITAR);
break;
case R.id.menu_buscar:
// Abre a tela para buscar o carro pelo nome
startActivity(new Intent(this, BuscarCarro.class));
break;
}
return true;
}
@Override
protected void onListItemClick(ListView l, View v, int posicao, long id) {
super.onListItemClick(l, v, posicao, id);
editarCarro(posicao);
}
// Recupera o id do carro, e abre a tela de edição
protected void editarCarro(int posicao) {
// Usuário clicou em algum carro da lista
// Recupera o carro selecionado
Carro carro = carros.get(posicao);
// Cria a intent para abrir a tela de editar
Intent it = new Intent(this, EditarCarro.class);
// Passa o id do carro como parâmetro
it.putExtra(Carros._ID, carro.id);
// Abre a tela de edição
startActivityForResult(it, INSERIR_EDITAR);
}
@Override
protected void onActivityResult(int codigo, int codigoRetorno, Intent it) {
super.onActivityResult(codigo, codigoRetorno, it);
// Quando a activity EditarCarro retornar, seja se foi para adicionar vamos atualizar a lista
if (codigoRetorno == RESULT_OK) {
// atualiza a lista na tela
atualizarLista();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
// Fecha o banco
repositorio.fechar();
}
}
I understand he’s saying he didn’t find this class above, but it does exist.
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.bancodedados"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:label="@string/app_name" android:name="CadastroCarros">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.example.bancodedados.EditarCarro" android:label="EditarCarro"/>
<activity android:name="com.example.bancodedados.BuscarCarro" android:label="BuscarCarro"/>
</application>
</manifest>