具有多个视图类型的ExpandableListView在Scroll等上崩溃

时间:2014-03-26 20:10:12

标签: java android expandablelistview android-query aquery

由于某些原因,我的expandableListView在Scroll或旋转更改时崩溃。我有两个此活动的视图类型

代码:

    @Override
    public int getGroupType(int groupPosition){
        return comments.get(groupPosition).is_load_more;
    }

    @Override
    public int getGroupTypeCount(){
        return 2;
    }

    @Override
    public View getGroupView(final int groupPosition, boolean isExpanded,  View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        View vi = convertView;
        final commentItem item = getGroup(groupPosition);
        if(vi == null) {
            holder = new ViewHolder();
            if(getGroupType(groupPosition) == 1){
                vi = mLayoutInflater.inflate(R.layout.comments_loadmore, null);
                holder.load_more = (Button)vi.findViewById(R.id.comments_load_more);
            }else{
                vi = mLayoutInflater.inflate(R.layout.comments_item, null);
                holder.aq = new AQuery(vi);
                holder.usericon = (ImageView)vi.findViewById(R.id.comments_item_userpic);
                holder.username = (TextView)vi.findViewById(R.id.comments_item_username);
                holder.fullname = (TextView)vi.findViewById(R.id.comments_item_fullname);
                holder.content = (TextView)vi.findViewById(R.id.comments_item_content);
                holder.commentc = (TextView)vi.findViewById(R.id.comments_item_commentcount);
                holder.commentBtn = (FrameLayout)vi.findViewById(R.id.comments_item_comment);
                holder.bumpBtn = (ImageView)vi.findViewById(R.id.comments_item_bump);
                holder.bumpc = (TextView)vi.findViewById(R.id.comments_item_countbump);
                holder.replyLayout = (LinearLayout)vi.findViewById(R.id.comments_item_replyLayout);
            }

        } else {
            holder = (ViewHolder) vi.getTag();
        }

        if(getGroupType(groupPosition) == 1){

        }else{
            holder.aq.id(R.id.comments_item_userpic).image(item.user_img, true, false, 96, 0);

logcat的:

E/AndroidRuntime( 9861): java.lang.NullPointerException
E/AndroidRuntime( 9861):        at test.com.CommentsActivity$commentAdapte
r.getGroupView(CommentsActivity.java:243)
E/AndroidRuntime( 9861):        at android.widget.ExpandableListConnector.getVie
w(ExpandableListConnector.java:446)
E/AndroidRuntime( 9861):        at android.widget.AbsListView.obtainView(AbsList
View.java:2268)
E/AndroidRuntime( 9861):        at android.widget.ListView.makeAndAddView(ListVi
ew.java:1790)
E/AndroidRuntime( 9861):        at android.widget.ListView.fillDown(ListView.jav
a:691)
E/AndroidRuntime( 9861):        at android.widget.ListView.fillSpecific(ListView
.java:1349)
E/AndroidRuntime( 9861):        at android.widget.ListView.layoutChildren(ListVi
ew.java:1641)
E/AndroidRuntime( 9861):        at android.widget.AbsListView.onLayout(AbsListVi
ew.java:2117)
E/AndroidRuntime( 9861):        at android.view.View.layout(View.java:14817)
E/AndroidRuntime( 9861):        at android.view.ViewGroup.layout(ViewGroup.java:
4631)
E/AndroidRuntime( 9861):        at android.widget.LinearLayout.setChildFrame(Lin
earLayout.java:1671)
E/AndroidRuntime( 9861):        at android.widget.LinearLayout.layoutVertical(Li
nearLayout.java:1525)
E/AndroidRuntime( 9861):        at android.widget.LinearLayout.onLayout(LinearLa
yout.java:1434)
E/AndroidRuntime( 9861):        at android.view.View.layout(View.java:14817)
E/AndroidRuntime( 9861):        at android.view.ViewGroup.layout(ViewGroup.java:
4631)
E/AndroidRuntime( 9861):        at android.widget.FrameLayout.layoutChildren(Fra
meLayout.java:453)
E/AndroidRuntime( 9861):        at android.widget.FrameLayout.onLayout(FrameLayo
ut.java:388)
E/AndroidRuntime( 9861):        at android.view.View.layout(View.java:14817)
E/AndroidRuntime( 9861):        at android.view.ViewGroup.layout(ViewGroup.java:
4631)
E/AndroidRuntime( 9861):        at com.android.internal.widget.ActionBarOverlayL
ayout.onLayout(ActionBarOverlayLayout.java:374)
E/AndroidRuntime( 9861):        at android.view.View.layout(View.java:14817)
E/AndroidRuntime( 9861):        at android.view.ViewGroup.layout(ViewGroup.java:
4631)
E/AndroidRuntime( 9861):        at android.widget.FrameLayout.layoutChildren(Fra
meLayout.java:453)
E/AndroidRuntime( 9861):        at android.widget.FrameLayout.onLayout(FrameLayo
ut.java:388)
E/AndroidRuntime( 9861):        at android.view.View.layout(View.java:14817)
E/AndroidRuntime( 9861):        at android.view.ViewGroup.layout(ViewGroup.java:
4631)
E/AndroidRuntime( 9861):        at android.view.ViewRootImpl.performLayout(ViewR
ootImpl.java:1987)
E/AndroidRuntime( 9861):        at android.view.ViewRootImpl.performTraversals(V
iewRootImpl.java:1744)
E/AndroidRuntime( 9861):        at android.view.ViewRootImpl.doTraversal(ViewRoo
tImpl.java:1000)
E/AndroidRuntime( 9861):        at android.view.ViewRootImpl$TraversalRunnable.r
un(ViewRootImpl.java:5670)
E/AndroidRuntime( 9861):        at android.view.Choreographer$CallbackRecord.run
(Choreographer.java:761)
E/AndroidRuntime( 9861):        at android.view.Choreographer.doCallbacks(Choreo
grapher.java:574)
E/AndroidRuntime( 9861):        at android.view.Choreographer.doFrame(Choreograp
her.java:544)
E/AndroidRuntime( 9861):        at android.view.Choreographer$FrameDisplayEventR
eceiver.run(Choreographer.java:747)
E/AndroidRuntime( 9861):        at android.os.Handler.handleCallback(Handler.jav
a:733)
E/AndroidRuntime( 9861):        at android.os.Handler.dispatchMessage(Handler.ja
va:95)
E/AndroidRuntime( 9861):        at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 9861):        at android.app.ActivityThread.main(ActivityThrea
d.java:5081)
E/AndroidRuntime( 9861):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime( 9861):        at java.lang.reflect.Method.invoke(Method.java:5
15)
E/AndroidRuntime( 9861):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:791)
E/AndroidRuntime( 9861):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:607)
E/AndroidRuntime( 9861):        at dalvik.system.NativeStart.main(Native Method)

它崩溃在“holder.aq.id(R.id.comments_item_userpic).image(item.user_img,true,false,96,0);”而且我不知道为什么。有谁可以帮助我?

1 个答案:

答案 0 :(得分:0)

我忘了添加                 vi.setTag(保持器); 在我第一次设置视图持有者之后。我的坏:希望这有助于任何有类似问题的人