Aula 03,
ao executar o projeto exibe a tela rapidamente e depois aparece a mensagem Unfortunately, CadastroCaelium.
Alguém pode me ajudar? aparentemente esta correto
Aparece isso no Log:
01-29 14:30:34.239: E/AndroidRuntime(1285): FATAL EXCEPTION: main
01-29 14:30:34.239: E/AndroidRuntime(1285): Process: br.com.caelum.cadastrocaelum, PID: 1285
01-29 14:30:34.239: E/AndroidRuntime(1285): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{br.com.caelum.cadastrocaelum/br.com.caelum.cadastrocael.ListaAlunosActivity}: java.lang.ClassNotFoundException: Didn't find class "br.com.caelum.cadastrocael.ListaAlunosActivity" on path: DexPathList[[zip file "/data/app/br.com.caelum.cadastrocaelum-2.apk"],nativeLibraryDirectories=[/data/app-lib/br.com.caelum.cadastrocaelum-2, /system/lib]]
Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.caelum.cadastrocaelum"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name="br.com.caelum.cadastrocael.ListaAlunosActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/lista_alunos"
android:layout_width="match_parent"
android:layout_height="match_parent"
></ListView>
</LinearLayout>
Classe
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import br.com.caelum.cadastrocaelum.R;
public class ListaAlunosActivity extends Activity{
private ListView listaAlunos;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String[] alunos = {"Douglas","Raphael","Vanuza"};
//layout pronto da classe R. do android
int layout = android.R.layout.simple_list_item_1;
//Criando o adpter para passar o array do Java para android
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, layout,alunos);
//fazendo a ponte entre XML e Java, e o devido Cast
listaAlunos=(ListView)findViewById(R.id.lista_alunos);
// Associar o adpter criado para o LIstView
listaAlunos.setAdapter(adapter);
// Atribuindo comportamentos Listener ao clicar no item da lista
listaAlunos.setOnItemClickListener(new OnItemClickListener() {
// ctrl+1 para implementar o metodo do contrato
@Override
public void onItemClick(AdapterView<?> adapter, View view, int posicao,
long id) {
// TODO Auto-generated method stub
Toast.makeText(ListaAlunosActivity.this, "A posição é: "+posicao, Toast.LENGTH_SHORT).show();
}
});
}
}