android - when slide fragment with gridview, it happens java.lang.NullPointerException -


i'm trying implement avtivity use viewpager fragment gridview in android. every gridview contains 8 apps icon of system , number of fragment dynamic. works slide third fragment. sorry english.

in current state of app, following exception:

   v/test_gridadapter( 1418): position 0, com.android.providers.downloads.ui getview v/test_gridadapter( 1418): position 0, com.android.providers.downloads.ui getview v/test_gridadapter( 1418): position 0, com.android.providers.downloads.ui getview v/test_gridadapter( 1418): position 0, com.android.providers.downloads.ui getview v/test_gridadapter( 1418): position 0, com.android.providers.downloads.ui getview v/test_gridadapter( 1418): position 1, com.android.quicksearchbox getview v/test_gridadapter( 1418): position 2, com.rockchip.gamecontrolsetting getview v/test_gridadapter( 1418): position 3, com.android.apkinstaller getview v/test_gridadapter( 1418): position 4, com.android.rockchip getview v/test_gridadapter( 1418): position 5, com.android.speechrecorder getview v/test_gridadapter( 1418): position 6, com.android.videoeditor getview v/test_gridadapter( 1418): position 7, com.rockchip.wfd getview v/test_gridadapter( 1418): position 0, com.rockchip.mediacenter getview v/test_gridadapter( 1418): position 0, com.rockchip.mediacenter getview v/test_gridadapter( 1418): position 0, com.rockchip.mediacenter getview v/test_gridadapter( 1418): position 0, com.rockchip.mediacenter getview v/test_gridadapter( 1418): position 0, com.rockchip.mediacenter getview d/androidruntime( 1418): shutting down vm w/dalvikvm( 1418): threadid=1: thread exiting uncaught exception (group=0x41c79300) e/androidruntime( 1418): fatal exception: main e/androidruntime( 1418): process: com.example.zhengjy.ljlauncher, pid: 1418 e/androidruntime( 1418): java.lang.nullpointerexception e/androidruntime( 1418):    @ com.example.zhengjy.ljlauncher.gridadapter.getview(gridadapter.java:95) e/androidruntime( 1418):    @ android.widget.abslistview.obtainview(abslistview.java:2263) e/androidruntime( 1418):    @ android.widget.gridview.makeandaddview(gridview.java:1345) e/androidruntime( 1418):    @ android.widget.gridview.makerow(gridview.java:345) e/androidruntime( 1418):    @ android.widget.gridview.filldown(gridview.java:287) e/androidruntime( 1418):    @ android.widget.gridview.fillfromtop(gridview.java:421) e/androidruntime( 1418):    @ android.widget.gridview.layoutchildren(gridview.java:1233) e/androidruntime( 1418):    @ android.widget.abslistview.onlayout(abslistview.java:2091) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) e/androidruntime( 1418):    @ android.widget.linearlayout.layoutvertical(linearlayout.java:1525) e/androidruntime( 1418):    @ android.widget.linearlayout.onlayout(linearlayout.java:1434) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.support.v4.view.viewpager.onlayout(viewpager.java:1626) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) e/androidruntime( 1418):    @ android.widget.linearlayout.layoutvertical(linearlayout.java:1525) e/androidruntime( 1418):    @ android.widget.linearlayout.onlayout(linearlayout.java:1434) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.framelayout.layoutchildren(framelayout.java:453) e/androidruntime( 1418):    @ android.widget.framelayout.onlayout(framelayout.java:388) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.relativelayout.onlayout(relativelayout.java:1055) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.framelayout.layoutchildren(framelayout.java:453) e/androidruntime( 1418):    @ android.widget.framelayout.onlayout(framelayout.java:388) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.linearlayout.setchildframe(linearlayout.java:1671) e/androidruntime( 1418):    @ android.widget.linearlayout.layoutvertical(linearlayout.java:1525) e/androidruntime( 1418):    @ android.widget.linearlayout.onlayout(linearlayout.java:1434) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.widget.framelayout.layoutchildren(framelayout.java:453) e/androidruntime( 1418):    @ android.widget.framelayout.onlayout(framelayout.java:388) e/androidruntime( 1418):    @ android.view.view.layout(view.java:14838) e/androidruntime( 1418):    @ android.view.viewgroup.layout(viewgroup.java:4631) e/androidruntime( 1418):    @ android.view.viewrootimpl.performlayout(viewrootimpl.java:1996) e/androidruntime( 1418):    @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1753) e/androidruntime( 1418):    @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1005) e/androidruntime( 1418):    @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5750) e/androidruntime( 1418):    @ android.view.choreographer$callbackrecord.run(choreographer.java:761) e/androidruntime( 1418):    @ android.view.choreographer.docallbacks(choreographer.java:574) e/androidruntime( 1418):    @ android.view.choreographer.doframe(choreographer.java:544) e/androidruntime( 1418):    @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) e/androidruntime( 1418):    @ android.os.handler.handlecallback(handler.java:733) e/androidruntime( 1418):    @ android.os.handler.dispatchmessage(handler.java:95) e/androidruntime( 1418):    @ android.os.looper.loop(looper.java:136) e/androidruntime( 1418):    @ android.app.activitythread.main(activitythread.java:5017) e/androidruntime( 1418):    @ java.lang.reflect.method.invokenative(native method) e/androidruntime( 1418):    @ java.lang.reflect.method.invoke(method.java:515) e/androidruntime( 1418):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:794) e/androidruntime( 1418):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:610) e/androidruntime( 1418):    @ dalvik.system.nativestart.main(native method) 

the activiy xml :

        <android.support.v4.view.viewpager             android:id="@+id/pager"             android:layout_width="match_parent"             android:layout_height="match_parent"         android:layout_marginbottom="1dp"         android:layout_weight="1" />          <com.viewpagerindicator.circlepageindicator             android:id="@+id/pagerindicator"             android:layout_width="match_parent"             android:layout_height="match_parent"             android:padding="3dp"             android:layout_gravity="bottom|center_horizontal"             android:layout_marginbottom="5dp"             android:layout_weight="5" /> 

the grid.xml is:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" >  <gridview     android:id="@+id/gridview"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:layout_margin="10dp"     android:layout_margintop="10dp"     android:horizontalspacing="100dp"     android:listselector="@android:color/transparent"     android:numcolumns="4"     android:stretchmode="columnwidth"     android:verticalspacing="2dp" /> 

the grid_item xml is:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/app_grid_item" android:layout_width="wrap_content" android:layout_height="match_parent" android:padding="@dimen/app_margin">  <imageview     android:id="@+id/app_icon"     android:layout_width="@dimen/grid_icon_width"     android:layout_height="@dimen/grid_icon_height"     android:layout_centerhorizontal="true"     android:visibility="visible" />  <relativelayout     android:id="@+id/label_container"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_below="@+id/app_icon"     android:layout_alignparentbottom="true">      <textview         android:id="@+id/app_name"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:gravity="center_horizontal"         android:minwidth="20dp"         android:ellipsize="end"         android:singleline="true"         android:padding="4dp"         android:textsize="15sp" /> </relativelayout> 

the gridadapter is:

public class gridadapter extends baseadapter {  context context;  private griditems[] items; private layoutinflater minflater;  public class viewholder {     public imageview imageview;     public textview texttitle; }  public gridadapter(context context, griditems[] items) {      minflater = (layoutinflater) context             .getsystemservice(context.layout_inflater_service);     this.context = context;     this.items = items;  }  ...  @override public void notifydatasetchanged() {     super.notifydatasetchanged(); }  @override public object getitem(int position) {     if (items != null && position >= 0 && position < getcount()) {         return items[position];     }     return null; }  @override public long getitemid(int position) {     if (items != null && position >= 0 && position < getcount()) {         return items[position].id;     }     return 0; }  public void setitemslist(griditems[] locations) {     this.items = locations; }  @override public view getview(int position, view convertview, viewgroup parent) {     viewholder viewholder;      if (convertview == null) {         convertview = minflater.inflate(r.layout.app_grid_item, parent, false);         viewholder = new viewholder();         viewholder.imageview = ((imageview) convertview.findviewbyid(r.id.app_icon));         viewholder.texttitle =  ((textview) convertview.findviewbyid(r.id.app_name));         convertview.settag(viewholder);     } else {         viewholder = (viewholder) convertview.gettag();     }     griditems griditems = items[position];     viewholder.imageview.setimagedrawable(griditems.appinfo.icon);     viewholder.texttitle.settext(griditems.appinfo.name);     log.v(tag, "the position " + position + ", " + griditems.appinfo.packagename + " getview");      return convertview; } 

}

the fragmentstatepageradapter :

   private class mypageradapter extends fragmentstatepageradapter {     private list<gridfragment> fragments;     fragmentmanager fm;      public mypageradapter(fragmentmanager fm, list<gridfragment> gridfragments) {         super(fm);         this.fm = fm;         this.fragments = gridfragments;     }      @override     public gridfragment getitem(int position) {         return this.fragments.get(position);     }      @override     public int getcount() {         return this.fragments.size();     } } 

}

the null pointer seems in getview() method. determine item null following:

public view getview(int position, view convertview, viewgroup parent) {     viewholder viewholder;      if (convertview == null) {         convertview = minflater.inflate(r.layout.app_grid_item, parent, false);         viewholder = new viewholder();         viewholder.imageview = ((imageview) convertview.findviewbyid(r.id.app_icon));         viewholder.texttitle =  ((textview) convertview.findviewbyid(r.id.app_name));         convertview.settag(viewholder);     } else {         viewholder = (viewholder) convertview.gettag();     }     if (viewholder == null) {         log.e("gridadapter", "viewholder null")         return convertview;     }     griditems griditems = items[position];     if (griditems == null || griditems.appinfo == null) {         log.e("gridadapter", "griditems or appinfo null")         return convertview;     }     viewholder.imageview.setimagedrawable(griditems.appinfo.icon);     viewholder.texttitle.settext(griditems.appinfo.name);     log.v(tag, "the position " + position + ", " + griditems.appinfo.packagename + " getview");      return convertview; } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -