java - Android compiles but crashes -


i trying develop first app. compiles , installs crashes when open it.

here code

public class mainactivity extends actionbaractivity implements onitemclicklistener { private  listview listview; private drawerlayout drawerlayout; private actionbardrawertoggle drawerlistener; private linearlayout menu; private myadapter myadapter; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);       listview=(listview)findviewbyid(r.id.listview);         myadapter=new myadapter(this);     listview.setonitemclicklistener(this);     listview.setadapter(myadapter);     drawerlayout=(drawerlayout)findviewbyid(r.id.drawerlayout);      drawerlistener= new actionbardrawertoggle(this,drawerlayout,r.drawable.ic_ic_drawer,r.string.app_name, r.string.app_name){             @override             public void ondrawerclosed(view drawerview) {                  toast.maketext(mainactivity.this, "ola", toast.length_long).show();                 menu=(linearlayout)findviewbyid(r.id.menu_lateral);                  menu.setvisibility(view.visible);                 super.ondrawerclosed(drawerview);          }                @override             public void ondraweropened(view drawerview) {                 menu=(linearlayout)findviewbyid(r.id.menu_lateral);                  menu.setvisibility(view.gone);                 super.ondraweropened(drawerview);             }     };         drawerlayout.setdrawerlistener(drawerlistener);     getsupportactionbar().sethomebuttonenabled(true);     getsupportactionbar().setdisplayhomeasupenabled(true);  }   @override public void onpostcreate(bundle savedinstancestate,         persistablebundle persistentstate) {     drawerlistener.syncstate();     super.onpostcreate(savedinstancestate, persistentstate); }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) { if(drawerlistener.onoptionsitemselected(item)){     return true; }     return super.onoptionsitemselected(item); }  @override public void onconfigurationchanged(configuration newconfig) {     // todo auto-generated method stub     super.onconfigurationchanged(newconfig);     drawerlistener.onconfigurationchanged(newconfig); }  @override public void onitemclick(adapterview<?> parent, view view, int position,         long id) {      class myadapter extends baseadapter{ private context context; view row=null; string [] menu; int [] images ={r.drawable.ic_contact, r.drawable.menu, r.drawable.ic_reservas, r.drawable.ic_map, r.drawable.galeria, r.drawable.info, r.drawable.facebook };  public myadapter(context context) { menu=context.getresources().getstringarray(r.array.slide); this.context=context; } @override public int getcount() {     // todo auto-generated method stub     return menu.length; } @override public object getitem(int position) {     // todo auto-generated method stub     return menu[position]; } @override public long getitemid(int position) {     // todo auto-generated method stub     return position; } @override public view getview(int position, view convertview, viewgroup parent) {     if(convertview==null){         view row=null;         layoutinflater inflater=(layoutinflater) context.getsystemservice(context.layout_inflater_service);         row=inflater.inflate(r.layout.custom_row, parent, false);     }     else     {         row=convertview;     }      textview titulo=(textview) row.findviewbyid(r.id.textview1);     imageview icone=(imageview) row.findviewbyid(r.id.imageview1);      titulo.settext(menu[position]);     icone.setimageresource(images[position]);     return row; } 

and here log cat

    06-13 18:55:12.842: d/openglrenderer(4763): render dirty regions requested: true 06-13 18:55:12.862: d/atlas(4763): validating map... 06-13 18:55:12.942: i/adreno-egl(4763): <qegldrvapi_eglinitialize:410>: egl 1.4 qualcomm build: au_linux_android_la.af.1.1.04.04.03.164.081_msm8960_la.af.1.1__release_au () 06-13 18:55:12.942: i/adreno-egl(4763): opengl es shader compiler version: e031.25.01.03 06-13 18:55:12.942: i/adreno-egl(4763): build date: 11/02/14 sun 06-13 18:55:12.942: i/adreno-egl(4763): local branch: mybranch5454281 06-13 18:55:12.942: i/adreno-egl(4763): remote branch: quic/l_lnx.la.3.6 06-13 18:55:12.942: i/adreno-egl(4763): local patches: none 06-13 18:55:12.942: i/adreno-egl(4763): reconstruct branch: au_linux_android_la.af.1.1.04.04.03.164.081 + db92d1e + cb8de02 +  nothing 06-13 18:55:12.942: i/openglrenderer(4763): initialized egl, version 1.4 06-13 18:55:12.972: d/openglrenderer(4763): enabling debug mode 0 06-13 18:55:13.072: d/androidruntime(4763): shutting down vm 06-13 18:55:13.102: e/androidruntime(4763): fatal exception: main 06-13 18:55:13.102: e/androidruntime(4763): process: com.example.alambique, pid: 4763 06-13 18:55:13.102: e/androidruntime(4763): java.lang.nullpointerexception: attempt invoke virtual method 'android.view.view android.view.view.findviewbyid(int)' on null object reference 06-13 18:55:13.102: e/androidruntime(4763):     @ com.example.alambique.myadapter.getview(mainactivity.java:155) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.abslistview.obtainview(abslistview.java:2346) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.listview.makeandaddview(listview.java:1864) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.listview.filldown(listview.java:698) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.listview.fillfromtop(listview.java:759) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.listview.layoutchildren(listview.java:1673) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.abslistview.onlayout(abslistview.java:2150) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.support.v4.widget.drawerlayout.onlayout(drawerlayout.java:931) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.onlayout(framelayout.java:508) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.onlayout(framelayout.java:508) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.support.v7.internal.widget.actionbaroverlaylayout.onlayout(actionbaroverlaylayout.java:493) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.onlayout(framelayout.java:508) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.linearlayout.onlayout(linearlayout.java:1466) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.layoutchildren(framelayout.java:573) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.widget.framelayout.onlayout(framelayout.java:508) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.view.layout(view.java:15596) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewgroup.layout(viewgroup.java:4966) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2072) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1829) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1054) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5786) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.choreographer$callbackrecord.run(choreographer.java:767) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.choreographer.docallbacks(choreographer.java:580) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.choreographer.doframe(choreographer.java:550) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.os.handler.handlecallback(handler.java:739) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.os.handler.dispatchmessage(handler.java:95) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.os.looper.loop(looper.java:135) 06-13 18:55:13.102: e/androidruntime(4763):     @ android.app.activitythread.main(activitythread.java:5256) 06-13 18:55:13.102: e/androidruntime(4763):     @ java.lang.reflect.method.invoke(native method) 06-13 18:55:13.102: e/androidruntime(4763):     @ java.lang.reflect.method.invoke(method.java:372) 06-13 18:55:13.102: e/androidruntime(4763):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:898) 06-13 18:55:13.102: e/androidruntime(4763):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:693) 06-13 18:55:13.162: i/process(4763): sending signal. pid: 4763 sig: 9 

view row=null; 

is defined twice local variable in if{} block, , class field in adapter. row variable here:

textview titulo=(textview) row.findviewbyid(r.id.textview1); imageview icone=(imageview) row.findviewbyid(r.id.imageview1); 

is declared adapter field, assigned null (probably avoid compiler complains) , never touched again. solution - declare variable in proper way.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -