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

FATAL EXCEPTION: main

07-01 21:24:51.385 3630-3630/br.com.calebe.agenda E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: br.com.calebe.agenda, PID: 3630
                                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.calebe.agenda/br.com.calebe.agenda.ListaAlunosActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                        at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                        at android.os.Looper.loop(Looper.java:148)
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setAdapter(android.widget.ListAdapter)' on a null object reference
                                                                        at br.com.calebe.agenda.ListaAlunosActivity.onCreate(ListaAlunosActivity.java:17)
                                                                        at android.app.Activity.performCreate(Activity.java:6237)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                        at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                        at android.os.Looper.loop(Looper.java:148) 
                                                                        at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                        at java.lang.reflect.Method.invoke(Native Method) 
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

activity_lista_alunos.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="horizontal">

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

</LinearLayout>

ListaAlunosActivity.java

package br.com.calebe.agenda;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
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"};
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, alunos);

        ListView listaAlunos = (ListView) findViewById(R.id.lista_alunos);
        listaAlunos.setAdapter(adapter);
    }
}
2 respostas
solução!

Seu código está correto.

Vá em Build -> Clean Project e rode novamente.

Valeu, deu certo!