Foros del Web » Programando para Internet » Android »

ListView me tira nullpointerexception

Estas en el tema de ListView me tira nullpointerexception en el foro de Android en Foros del Web. Estoy tratando de hacer un adaptador personalizado con algún otro ejemplo que tengo y la unica diferencia que veo es que extiendo de ActionBarActivity en ...
  #1 (permalink)  
Antiguo 03/02/2015, 11:44
 
Fecha de Ingreso: mayo-2011
Ubicación: Entre Navarra y Aragón
Mensajes: 96
Antigüedad: 12 años, 11 meses
Puntos: 0
ListView me tira nullpointerexception

Estoy tratando de hacer un adaptador personalizado con algún otro ejemplo que tengo y la unica diferencia que veo es que extiendo de ActionBarActivity en vez de Activity y no se si por eso me da fallo, podría ser?

os dejo algo de mi código


index.java
Código Java:
Ver original
  1. public class Index extends ActionBarActivity implements NavigationDrawerFragment.NavigationDrawerCallbacks {
  2.     private NavigationDrawerFragment mNavigationDrawerFragment;
  3.     private CharSequence mTitle;
  4.     private ArrayList<Evento> event;
  5.     private AdaptadorEventos adaptador;
  6.     private ListView listaEventos;
  7.  
  8.     @Override
  9.     protected void onCreate(Bundle savedInstanceState) {
  10.         super.onCreate(savedInstanceState);
  11.        
  12.         setContentView(R.layout.index);
  13.         new LoadIconTask().execute(R.id.section_label);
  14.         mNavigationDrawerFragment = (NavigationDrawerFragment)getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
  15.         mTitle = getTitle();
  16.         mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
  17.  
  18.        
  19.         event=new ArrayList<Evento>();
  20.         event.add(new Evento(1,1,"aaa","aaa","aaa","aaa"));
  21.         event.add(new Evento(2,2,"bbb","bbb","bbb","bbb"));
  22.        
  23.         adaptador=new AdaptadorEventos(this, event);
  24.         listaEventos = (ListView)findViewById(R.id.lstEventos);
  25.         listaEventos.setAdapter(adaptador); //Esta es la línea que me da fallo    
  26.         registerForContextMenu(listaEventos);
  27.     }

AdaptadorEventos.java
Código Java:
Ver original
  1. public class AdaptadorEventos extends ArrayAdapter<Evento>{
  2.     private Context context;
  3.     private ArrayList<Evento> evento;
  4.     public AdaptadorEventos(Context context, ArrayList<Evento> evento) {
  5.         super(context, R.layout.activity_main, evento);
  6.         this.context = context;
  7.         this.evento = evento;
  8.     }
  9.     public View getView(int position, View convertView, ViewGroup parent){
  10.         LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  11.         View item = inflater.inflate(R.layout.adaptador_eventos, null);
  12.         TextView lblTitulo = (TextView)item.findViewById(R.id.lblB);
  13.         lblTitulo.setText(evento.get(position).getIdBanda());
  14.         TextView lblSubtitulo = (TextView)item.findViewById(R.id.lblR);
  15.         lblSubtitulo.setText(evento.get(position).getIdRecinto());
  16.         return (item);
  17.     }
  18. }

Fragment_main.xml
Código XML:
Ver original
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.    xmlns:tools="http://schemas.android.com/tools"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent"
  5.    android:paddingBottom="@dimen/activity_vertical_margin"
  6.    android:paddingLeft="@dimen/activity_horizontal_margin"
  7.    android:paddingRight="@dimen/activity_horizontal_margin"
  8.    android:paddingTop="@dimen/activity_vertical_margin"
  9.    tools:context="es.plugme.MainActivity$PlaceholderFragment"
  10.    android:background="#f3f3f3" >
  11.  
  12.     <TextView
  13.        android:id="@+id/section_label"
  14.        android:layout_width="wrap_content"
  15.        android:layout_height="wrap_content"
  16.        android:text="Hola" />
  17.     <ListView
  18.        android:id="@+id/lstEventos"
  19.        android:layout_width="wrap_content"
  20.        android:layout_height="wrap_content"
  21.        android:text="Hola" />
  22.  
  23. </RelativeLayout>

adaptador_eventos.xml
Código XML:
Ver original
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout
  3.     xmlns:android="http://schemas.android.com/apk/res/android"
  4.     android:layout_width="wrap_content"
  5.     android:layout_height="wrap_content"
  6.     android:orientation="vertical">
  7.     <TextView android:id="@+id/lblB"
  8.         android:layout_width="fill_parent"
  9.         android:layout_height="wrap_content"
  10.         android:textStyle="bold"
  11.         android:textSize="20dp"
  12.         android:layout_marginLeft="10dp"/>
  13.     <TextView android:id="@+id/lblR"
  14.         android:layout_width="fill_parent"
  15.         android:layout_height="wrap_content"
  16.         android:textStyle="normal"
  17.         android:textSize="12dp"
  18.         android:paddingTop="20dp"
  19.         android:layout_marginLeft="10dp"/>
  20. </RelativeLayout>

En teoría no tengo nada más y por otros ejemplos que tengo y he probado así debería funcionar... pero no entiendo porque no :/

Etiquetas: activity, androi, list, listview, tira, view
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:55.