estou com o seguinte erro ao tentar rodar a aplicação:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.cadastroDeAluno, PID: 9519
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ListView.setOnItemClickListener(android.widget.AdapterView$OnItemClickListener)' on a null object reference
at br.com.cadastroDeAluno.ListarAlunosFragment.onCreateView(ListarAlunosFragment.java:58)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2080)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1108)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1638)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1240)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1088)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
at android.view.View.measure(View.java:19169)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
at android.view.View.measure(View.java:19169)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:19169)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:389)
at android.view.View.measure(View.java:19169)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at android.view.View.measure(View.java:19169)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1723)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:788)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:648)
at android.view.View.measure(View.java:19169)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6113)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:223)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2720)
at android.view.View.measure(View.java:19169)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2481)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1440)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1694)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6737)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894)
at android.view.Choreographer.doCallbacks(Choreographer.java:696)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
I/Process: Sending signal. PID: 9519 SIG: 9
Application terminated.
classe:
package br.com.cadastroDeAluno;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import java.util.List;
import br.com.cadastroDeAluno.adapter.AlunosAdapter;
import br.com.cadastroDeAluno.dao.AlunoDAO;
import br.com.cadastroDeAluno.modelo.Aluno;
/**
* A simple {@link Fragment} subclass.
*/
public class ListarAlunosFragment extends Fragment {
//private static final int PERMISSION_RECEIVER_SMS = 123;
private ListView listaAlunos;
private View meuFragment;
/**
* public ListarAlunosFragment() {
* // Required empty public constructor
* }
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
meuFragment = inflater.inflate(R.layout.fragment_listar_alunos, container, false);
//listaAlunos = (ListView)findViewById(R.id.lista_alunos);
//listaAlunos.setEmptyView(findViewById(R.id.list_vazia));
//mostrar a logo na tela do App
//getSupportActionBar().setDisplayShowHomeEnabled(true);
//getSupportActionBar().setIcon(R.mipmap.ic_students);
setHasOptionsMenu(true);
// ---- selecionando um aluno da lista p/ editar/atualizar no formulario ----
listaAlunos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> lista, View item, int position, long id) {
Aluno aluno = (Aluno) lista.getItemAtPosition(position);
Intent intentAlunoParaFormulario = new Intent(getActivity(), FormularioActivity.class);
intentAlunoParaFormulario.putExtra("Aluno", aluno);
startActivity(intentAlunoParaFormulario);
}
});
//---------------------------------------------------------------------------
// ----- botao novoAluno ----
final Button novoAluno = (Button) meuFragment.findViewById(R.id.novo_aluno);
novoAluno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intentVaiParaFormulario = new Intent(getActivity(), FormularioActivity.class);
startActivity(intentVaiParaFormulario);
}
});
//-------------------------------------------------------------------------
// ---- menu no contexto na lista ----
registerForContextMenu(listaAlunos);
return meuFragment;
}
public void carregaLista() {
AlunoDAO dao = new AlunoDAO(getActivity());
List<Aluno> alunos = dao.buscaAlunos();
dao.close();
//criando um AlunosAdapter
AlunosAdapter adapter = new AlunosAdapter(getActivity(), alunos);//alem de passar um aluno tem q ser passado um contexto (this) para o adapter.
listaAlunos.setAdapter(adapter);
}
@Override
public void onResume() {
super.onResume();
carregaLista();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu_lista_alunos, menu);
super.onCreateOptionsMenu(menu, inflater);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_enviar_notas:
//new EnviaAlunosTask(this).execute(); essa linha mostra a resposta do json
//Intent vaiParaMediaDosAlunos = new Intent(this, ListarMediasFragment.class);
//s/tartActivity(vaiParaMediaDosAlunos);
break;
case R.id.menu_baixar_provas:
Intent vaiParaProvas = new Intent(getActivity(), ProvasActivity.class);
startActivity(vaiParaProvas);
break;
case R.id.menu_mapa:
Intent vaiParaMapa = new Intent(getActivity(), MapaActivity.class);
startActivity(vaiParaMapa);
break;
}
return super.onOptionsItemSelected(item);
}
// ----- codigo do menu no contexto na lista de alunos ------
@Override
public void onCreateContextMenu(ContextMenu menu, View v, final ContextMenu.ContextMenuInfo menuInfo) {
//-- recuperando o aluno clicado --------------
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
final Aluno aluno = (Aluno) listaAlunos.getItemAtPosition(info.position);
// --------------------------------------------
//-- menu no contexto - ligar --------
MenuItem ItemLigar = menu.add("Fazer ligação");
Intent intentLigar = new Intent(Intent.ACTION_VIEW);
intentLigar.setData(Uri.parse("tel:" + aluno.getTelefone()));
ItemLigar.setIntent(intentLigar);
//--------------------------------------------------
//-- menu no contexto - enviar sms --------
MenuItem ItemSMS = menu.add("Enviar SMS");
Intent intentSMS = new Intent(Intent.ACTION_VIEW);
intentSMS.setData(Uri.parse("sms:" + aluno.getTelefone()));
ItemSMS.setIntent(intentSMS);
//--------------------------------------------------
//-- menu item deletar no contexto -----------
MenuItem deletar = menu.add("Deletar");
deletar.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
//deletando do aluno
AlunoDAO dao = new AlunoDAO(getActivity());
dao.deleta(aluno);
dao.close();
//mostrando mensagem e atualizando a lista
Toast.makeText(getActivity(), "Aluno " + aluno.getNome() + " deletado com sucesso!", Toast.LENGTH_SHORT).show();
carregaLista();
return false;
}
});
//-----------------------------------------------------
//@Override
//public void onRequestPermissionResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantTesults) {
//super.onRequestPermissionResult(requestCode, permissions, grantResults);
// if (requestCode == 123) {
// faz a ligacao
// }
//}
}
}
o que posso fazer?