java - NullPointerException ArrayAdapter adapter Android XML -


how you? come android problem, nullpointerexception arrayadapter adapter.im junior development, sorry.

i have code

private string[] titulares; private listview listadotitulos;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      //permisos     strictmode.threadpolicy permiso = new  strictmode.threadpolicy.builder().permitall().build();     //damos los permisos     strictmode.setthreadpolicy(permiso);     listadotitulos = (listview) findviewbyid(r.id.lvtitulos);     try {         url = new url("http://www.videotutoriales.es/android-xml/cursos.xml");         leerxml();     } catch (malformedurlexception e) {         e.printstacktrace();     }      arrayadapter<string> adapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1,titulares);     listadotitulos.setadapter(adapter); } 

the nullpointerexception arrayadapter in logcat

05-12 03:25:18.807  32599-32599/com.cig.trlxml e/androidruntime﹕ fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.cig.trlxml/com.cig.trlxml.mainactivity}: java.lang.nullpointerexception 

in line

arrayadapter<string> adapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1,titulares);     listadotitulos.setadapter(adapter); 

the xml file is

<relativelayout 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" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity">  <imageview     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:id="@+id/imageview"     android:layout_alignparentright="true"     android:layout_alignparentend="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:src="@mipmap/logon" />  <listview     android:layout_width="wrap_content"     android:layout_height="match_parent"     android:id="@+id/lvtitulos"     android:layout_below="@+id/imageview"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true" /> 

what wrong?

thank you

edit

private void leerxml() {     //es necesario para utilizar la clase xmlpullparser     xmlpullparserfactory factory;     xmlpullparser xml;     //variable para los eventos     int evento;     boolean titulo;     arraylist<string> titulos;     //puedo leer el titulo?     titulo = false;     titulos = new arraylist<string>();     try {         factory = xmlpullparserfactory.newinstance();         xml=factory.newpullparser();         //obtenemos la url         xml.setinput(url.openstream(),"utf-8");          evento = xml.geteventtype();         //leer cada uno de los eventos hasta el final         while (evento != xmlpullparser.end_document){             switch(evento){                 case xmlpullparser.start_tag:                     if(xml.getname().equals("titulo")){                         titulo = true;                     }                     break;                 case  xmlpullparser.text:                     if(titulo = true){                         titulos.add(xml.gettext());                     }                     break;                 case xmlpullparser.end_tag:                     if(xml.getname().equals("titulo")) {                         titulo = false;                     }                     break;             }             evento = xml.next();         }          titulares = new string[titulos.size()];         (int = 0; i< titulos.size(); i++){             titulares[i] = titulos.get(i);         }          } catch (ioexception e) {             e.printstacktrace();         } catch (xmlpullparserexception e) {         e.printstacktrace();     }  } 

the reason fr exception neved initialize titulares array, try use data when creating adapter :

arrayadapter<string> adapter = new arrayadapter<string>(this,android.r.layout.simple_list_item_1,titulares);     listadotitulos.setadapter(adapter); 

just code this:

titulares = new string[your_lenght]; 

before adapter creating or full content if have there


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -