java - Android user interface coding error -


so, i've had problems adding buttons through coding. error message logcat when activity supposed things:

09-30 09:36:51.591: e/androidruntime(14956): java.lang.runtimeexception: unable start activity componentinfo{com.example.gameproj/com.example.gameproj.mapmain}: java.lang.nullpointerexception 

here's code seems relevant:

        map = new button[loadedmap.getx()][loadedmap.gety()];         linearlayout layout = (linearlayout) findviewbyid(r.id.mapything);         linearlayout.layoutparams coord;         (int = 0; < map.length; i++){             (int j = 0; j < map[i].length; j++){                 map[i][j] = new button(this);                 coord = new layoutparams(16*i, 75+16*j);                 map[i][j].setlayoutparams(coord);                 map[i][j].setgravity(gravity.center_horizontal);                 layout.addview(map[i][j]);             }         } 

from debug, error around layout.addview(map[i][j]) line, i've been unable find out how work.

edit: i'm not sure else put, i'll go ahead , put xml file see if it'll make more clear

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/mapything"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="${relativepackage}.${activityclass}" >      <button         android:id="@+id/button1"         style="?android:attr/buttonstylesmall"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:onclick="tocharacter"         android:text="back" />      <textview         android:id="@+id/textview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignbaseline="@+id/button1"         android:layout_alignbottom="@+id/button1"         android:layout_centerhorizontal="true"         android:text="map"         android:textsize="18sp" />  </relativelayout> 

i think problem in line for (int j = 0; j < map[i].length; i++) try replace for (int j = 0; j < map[i].length; j++).


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -