Lo que quiero hacer es que listView muestre los datos, tengo el siguiente fallo:
05-27 19:26:59.412 13176-13176/com.example.pc.libreta E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.pc.libreta, PID: 13176 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pc.libreta/com.example.pc.libreta.Activities.MainActivity}: 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 com.example.pc.libreta.Activities.MainActivity.onCreate(MainActivity.java:90) at android.app.Activity.performCreate(Activity.java:6251) 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)
MAINACTIVITY
package com.example.pc.libreta.Activities;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import com.example.pc.libreta.Fragments.AnadirPersonaFragment;
import com.example.pc.libreta.Fragments.BuscarPersonasFragment;
import com.example.pc.libreta.Fragments.ListadoPersonasFragment;
import com.example.pc.libreta.R;
import com.example.pc.libreta.dataBase.DBHelper;
import com.example.pc.libreta.dataBase.PersonasQuotes;
import com.example.pc.libreta.models.AdaptadorPersonas;
import com.example.pc.libreta.models.Personas;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private DrawerLayout drawerLayout;
private NavigationView navigationView;
private ListView mListView;
private AdaptadorPersonas mAdaptadorPersonas;
private ArrayList<Personas> datos = new ArrayList<Personas>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setToolbar();
DBHelper dbHelper = new DBHelper(this);
SQLiteDatabase database = dbHelper.getReadableDatabase();
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.navView);
setFragmentDefault();
Cursor cursor = database.rawQuery("SELECT * FROM " + PersonasQuotes.PersonasTabla.NOMBRE_TABLA, null);
while(cursor.moveToNext()){
int id = cursor.getInt(cursor.getColumnIndex(PersonasQuotes.PersonasTabla._ID));
String nombre = cursor.getString(cursor.getColumnIndex(PersonasQuotes.PersonasTabla.NOMBRE));
String apellidos = cursor.getString(cursor.getColumnIndex(PersonasQuotes.PersonasTabla.APELLIDOS));
datos.add(new Personas(id, nombre, apellidos, null, null, null, null, null,null, null,
0, false, null, null));
}
//Metemos el Fragmente Listado de Personas en nuestra Activity//
mListView = (ListView) findViewById(R.id.listViewDetails);
this.mAdaptadorPersonas = new AdaptadorPersonas(this, R.layout.list_personas_detalle, datos) {
@Override
public void onEntrada(Object entrada, View view) {
TextView nombre = (TextView) view.findViewById(R.id.textViewNombre);
nombre.setText(((Personas)entrada).getNombre());
TextView apellidos = (TextView) view.findViewById(R.id.textViewApellidos);
apellidos.setText(((Personas)entrada).getApellidos());
TextView fecha = (TextView) view.findViewById(R.id.textViewFecha);
fecha.setText(((Personas)entrada).getFechaNacimiento());
}
};
mListView.setAdapter(mAdaptadorPersonas);
//MENU DE NAVEGACIÓN//
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
boolean fragmentTransaccion = false;
Fragment fragment = null;
switch (item.getItemId()){
case R.id.principal:
fragment = new ListadoPersonasFragment();
fragmentTransaccion = true;
break;
case R.id.anadir_personas:
fragment = new AnadirPersonaFragment();
fragmentTransaccion = true;
break;
case R.id.buscar_personas:
fragment = new BuscarPersonasFragment();
fragmentTransaccion = true;
break;
case R.id.anadir_placa:
fragment = new ListadoPersonasFragment();
fragmentTransaccion = true;
break;
}
if (fragmentTransaccion){
changeFragment(fragment, item);
}
return false;
}
});
//FIN MENU DE NAVEGACIÓN//
}
//TOOLBAR//
private void setToolbar(){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_name);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
//FIN TOOLBAR//
private void changeFragment(Fragment fragment, MenuItem menuItem){
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, fragment)
.commit();
menuItem.setChecked(true);
getSupportActionBar().setTitle(menuItem.getTitle());
drawerLayout.closeDrawers();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
drawerLayout.openDrawer(GravityCompat.START);
return true;
}
return super.onOptionsItemSelected(item);
}
private void setFragmentDefault(){
changeFragment(new ListadoPersonasFragment(), navigationView.getMenu().getItem(0));
}
}
fragment_listado_personas
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.pc.libretapolicial.Fragments.ListadoPersonasFragment">
<ListView
android:id="@+id/listViewDetails"
android:layout_width="match_parent"
android:layout_height="match_parent" />
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/navView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/menu"/>
¿Dónde tengo el fallo?