Android的ExpandableListView NullPointerException异常的ObtainView异常、ExpandableListView、Android、ObtainView

2023-09-07 22:14:40 作者:浊酒一杯温如言

我想用一个简单的ExpandableListView工作,我想不通,为什么我得到的NPE在ObtainView。我应该只有一个父和几个孩子应开设在点击他们的父母,但它总是崩溃,并显示在ObtainView NullPointerException异常。非常感谢!

Prima.java:

 包com.descoper.rom;

进口的java.util.ArrayList;

进口android.app.ExpandableListActivity;
进口android.content.Context;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.widget.ExpandableListView;

公共类厦华扩展ExpandableListActivity
{
    //创建ArrayList中持有父项和子项
    私人的ArrayList<字符串> parentItems =新的ArrayList<字符串>();
    私人的ArrayList<对象> childItems =新的ArrayList<对象>();

    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {

        super.onCreate(savedInstanceState);


        //创建扩展列表,并设置其属性
        ExpandableListView expandableList = getExpandableListView();
        expandableList.setDividerHeight(2);
        expandableList.setGroupIndicator(空);
        expandableList.setClickable(真正的);

        //设置家长的项目
        setGroupParents();
        //设置子数据
        setChildData();

        //创建适配器
        转接适配器=新的适配器(parentItems,childItems);

        adapter.setInflater((LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE),这一点);

        //设置适配器expandableList
        expandableList.setAdapter(适配器);
        expandableList.setOnChildClickListener(本);
    }

    //方法添加父项目
    公共无效setGroupParents()
    {
        parentItems.add(Categorii);
    }

    //方法来设置每个父母的子数据
    公共无效setChildData()
    {

        //添加子项的水果
        ArrayList的<字符串>孩子=新的ArrayList<字符串>();
        child.add(苹果);
        child.add(芒果);
        child.add(香蕉);
        child.add(橙);

        childItems.add(子);

    }

}
 

Adapter.java:

 包com.descoper.rom;

进口的java.util.ArrayList;

进口android.app.Activity;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.view.ViewGroup;
进口android.widget.BaseExpandableListAdapter;
进口android.widget.CheckedTextView;
进口android.widget.TextView;
进口android.widget.Toast;

公共类适配器扩展BaseExpandableListAdapter
{

    私人活动的活动;
    私人的ArrayList<对象> childtems;
    私人LayoutInflater充气;
    私人的ArrayList<字符串> parentItems,儿童;

    //构造
    公共适配器(ArrayList中<字符串>父母的ArrayList<对象>子女)
    {
        this.parentItems =父母;
        this.childtems =子女;
    }

    公共无效setInflater(LayoutInflater充气,活动活动)
    {
        this.inflater =充气;
        this.activity =活动;
    }

    //方法getChildView自动为每个子视图调用。
    公共查看getChildView1(INT groupPosition,最终诠释childPosition,布尔isLastChild,查看convertView,父母的ViewGroup)
    {

        孩子=(ArrayList的<字符串>)childtems.get(groupPosition);

        TextView中的TextView = NULL;

        如果(convertView == NULL){
            convertView = inflater.inflate(R.layout.child,NULL);
        }

         //获取TextView的参考和设定值
        TextView的=(的TextView)convertView.findViewById(R.id.textViewChild);
        textView.setText(child.get(childPosition));

        //设置ClickListener来处理子项的单击事件
        convertView.setOnClickListener(新OnClickListener(){

            公共无效的onClick(视图查看){
                Toast.makeText(活动,child.get(childPosition)
                        Toast.LENGTH_SHORT).show();
            }
        });
        返回convertView;
    }

    //方法getGroupView自动为每个父项目称为
    公共查看getGroupView1(INT groupPosition,布尔isExpanded,查看convertView,父母的ViewGroup)
    {

        如果(convertView == NULL){
            convertView = inflater.inflate(R.layout.categorii,NULL);
        }

        ((CheckedTextView)convertView).setText(parentItems.get(groupPosition));
        ((CheckedTextView)convertView).setChecked(isExpanded);

        返回convertView;
    }

    @覆盖
    公共对象getChild(INT groupPosition,INT childPosition)
    {
        返回null;
    }

    @覆盖
    众长getChildId(INT groupPosition,INT childPosition)
    {
        返回0;
    }

    @覆盖
    公众诠释getChildrenCount(INT groupPosition)
    {
        返程((ArrayList中<字符串>)childtems.get(groupPosition))的大小()。
    }

    @覆盖
    公共对象getGroup(INT groupPosition)
    {
        返回null;
    }

    @覆盖
    公众诠释getGroupCount()
    {
        返回parentItems.size();
    }

    @覆盖
    公共无效onGroupCollapsed(INT groupPosition)
    {
        super.onGroupCollapsed(groupPosition);
    }

    @覆盖
    公共无效onGroupExpanded(INT groupPosition)
    {
        super.onGroupExpanded(groupPosition);
    }

    @覆盖
    众长getGroupId(INT groupPosition)
    {
        返回0;
    }

    @覆盖
    公共布尔hasStableIds()
    {
        返回false;
    }

    @覆盖
    公共布尔isChildSelectable(INT groupPosition,INT childPosition)
    {
        返回false;
    }

    @覆盖
    公共查看getGroupView(INT groupPosition,布尔isExpanded,
            查看convertView,ViewGroup中父){
        // TODO自动生成方法存根
        返回null;
    }

    @覆盖
    公共查看getChildView(INT groupPosition,INT childPosition,
            布尔isLastChild,查看convertView,ViewGroup中父){
        // TODO自动生成方法存根
        返回null;
    }

}
 

parent.xml:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直
    机器人:背景=@可绘制/ backg1
    机器人:重力=中心|顶
     >

    < CheckedTextView
        的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
        的xmlns:工具=htt​​p://schemas.android.com/tool​​s
        机器人:ID =@ + ID / textViewGroupName
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =60dp
        机器人:layout_marginLeft =5DP
        机器人:重力=center_vertical
        机器人:文本=Categorii
        机器人:TEXTSIZE =18dp
        机器人:文字颜色=#FFFFFF
        机器人:填充=10dp
        机器人:TEXTSTYLE =黑体/>

< / LinearLayout中>
 
Android ExpandableListView

child.xml:

 < LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =40dp

    机器人:可点击=真
    机器人:方向=垂直
    机器人:以下属性来=40dp
     >

    <的LinearLayout
        机器人:layout_width =match_parent
        机器人:layout_height =39dp
        机器人:重力=center_vertical>

        < ImageView的
            机器人:ID =@ + ID / childImage
            机器人:layout_width =30dp
            机器人:layout_height =30dp
            机器人:layout_margin =5DP
            机器人:背景=@可绘制/ ic_launcher
            机器人:contentDescription =@空/>

        <的TextView
            机器人:ID =@ + ID / textViewChild
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_marginLeft =5DP
            机器人:文本=Categorii
            机器人:TEXTSIZE =16SP
            机器人:文字颜色=#1919A3
            机器人:TEXTSTYLE =黑体/>
    < / LinearLayout中>

    <查看
        机器人:layout_width =match_parent
        机器人:layout_height =1DP
        机器人:背景=@机器人:彩色/白/>

< / LinearLayout中>
 

logcat的:

  10月5日至一十九号:18:25.180:E / AndroidRuntime(1361):致命异常:主要
10月5号至19日:18:25.180:E / AndroidRuntime(1361):工艺:com.descoper.rom,PID:1361
10月5号至19日:18:25.180:E / AndroidRuntime(1361):显示java.lang.NullPointerException
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.AbsListView.obtainView(AbsListView.java:2265)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.ListView.makeAndAddView(ListView.java:1790)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.ListView.fillDown(ListView.java:691)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.ListView.fillFromTop(ListView.java:752)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.ListView.layoutChildren(ListView.java:1630)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.AbsListView.onLayout(AbsListView.java:2091)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.View.layout(View.java:14817)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewGroup.layout(ViewGroup.java:4631)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.FrameLayout.onLayout(FrameLayout.java:388)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.View.layout(View.java:14817)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewGroup.layout(ViewGroup.java:4631)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.View.layout(View.java:14817)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewGroup.layout(ViewGroup.java:4631)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.widget.FrameLayout.onLayout(FrameLayout.java:388)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.View.layout(View.java:14817)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewGroup.layout(ViewGroup.java:4631)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5670)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:761)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.Choreographer.doCallbacks(Choreographer.java:574)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.Choreographer.doFrame(Choreographer.java:544)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:747)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.os.Handler.handleCallback(Handler.java:733)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.os.Handler.dispatchMessage(Handler.java:95)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.os.Looper.loop(Looper.java:136)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在android.app.ActivityThread.main(ActivityThread.java:5017)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在java.lang.reflect.Method.invokeNative(本机方法)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在java.lang.reflect.Method.invoke(Method.java:515)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
10月5号至19日:18:25.180:E / AndroidRuntime(1361):在dalvik.system.NativeStart.main(本机方法)
 

解决方案

您在返回 getChild() getGroup()。你应该从你的数据结构返回相应的组和子项。

另外,你正在返回 getChildView() getGroupView()。在这里,你应该返回一个查看,将重新present孩子和组浏览分别。

我建议你阅读有关 适配器 以及它们如何工作。

I'm trying to work with a simple ExpandableListView and I can't figure out why I get that NPE at ObtainView. I should have only one parent and few more children which should be opened on click on the parent of them, but it keeps crashing and showing NullPointerException on ObtainView. Thanks a lot !

Prima.java:

package com.descoper.rom;

import java.util.ArrayList;

import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ExpandableListView;

public class Prima extends ExpandableListActivity
{
    // Create ArrayList to hold parent Items and Child Items
    private ArrayList<String> parentItems = new ArrayList<String>();
    private ArrayList<Object> childItems = new ArrayList<Object>();

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {

        super.onCreate(savedInstanceState);


        // Create Expandable List and set it's properties
        ExpandableListView expandableList = getExpandableListView(); 
        expandableList.setDividerHeight(2);
        expandableList.setGroupIndicator(null);
        expandableList.setClickable(true);

        // Set the Items of Parent
        setGroupParents();
        // Set The Child Data
        setChildData();

        // Create the Adapter
        Adapter adapter = new Adapter(parentItems, childItems);

        adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this);

        // Set the Adapter to expandableList
        expandableList.setAdapter(adapter);
        expandableList.setOnChildClickListener(this);
    }

    // method to add parent Items
    public void setGroupParents() 
    {
        parentItems.add("Categorii");
    }

    // method to set child data of each parent
    public void setChildData() 
    {

        // Add Child Items for Fruits
        ArrayList<String> child = new ArrayList<String>();
        child.add("Apple");
        child.add("Mango");
        child.add("Banana");
        child.add("Orange");

        childItems.add(child);

    }

}

Adapter.java:

package com.descoper.rom;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import android.widget.Toast;

public class Adapter extends BaseExpandableListAdapter 
{

    private Activity activity;
    private ArrayList<Object> childtems;
    private LayoutInflater inflater;
    private ArrayList<String> parentItems, child;

    // constructor
    public Adapter(ArrayList<String> parents, ArrayList<Object> childern)
    {
        this.parentItems = parents;
        this.childtems = childern;
    }

    public void setInflater(LayoutInflater inflater, Activity activity) 
    {
        this.inflater = inflater;
        this.activity = activity;
    }

    // method getChildView is called automatically for each child view.
    public View getChildView1(int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) 
    {

        child = (ArrayList<String>) childtems.get(groupPosition);

        TextView textView = null;

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.child, null);
        }

         // get the textView reference and set the value
        textView = (TextView) convertView.findViewById(R.id.textViewChild);
        textView.setText(child.get(childPosition));

        // set the ClickListener to handle the click event on child item
        convertView.setOnClickListener(new OnClickListener() {

            public void onClick(View view) {
                Toast.makeText(activity, child.get(childPosition),
                        Toast.LENGTH_SHORT).show();
            }
        });
        return convertView;
    }

    // method getGroupView is called automatically for each parent item
    public View getGroupView1(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) 
    {

        if (convertView == null) {
            convertView = inflater.inflate(R.layout.categorii, null);
        }

        ((CheckedTextView) convertView).setText(parentItems.get(groupPosition));
        ((CheckedTextView) convertView).setChecked(isExpanded);

        return convertView;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) 
    {
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) 
    {
        return 0;
    }

    @Override
    public int getChildrenCount(int groupPosition) 
    {
        return ((ArrayList<String>) childtems.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) 
    {
        return null;
    }

    @Override
    public int getGroupCount() 
    {
        return parentItems.size();
    }

    @Override
    public void onGroupCollapsed(int groupPosition) 
    {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition)
    {
        super.onGroupExpanded(groupPosition);
    }

    @Override
    public long getGroupId(int groupPosition) 
    {
        return 0;
    }

    @Override
    public boolean hasStableIds() 
    {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition)
    {
        return false;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        return null;
    }

}

parent.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/backg1"
    android:gravity="center|top"
     >

    <CheckedTextView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/textViewGroupName"
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:layout_marginLeft="5dp"
        android:gravity="center_vertical"
        android:text="Categorii"
        android:textSize="18dp"
        android:textColor="#FFFFFF"
        android:padding="10dp"
        android:textStyle="bold" /> 

</LinearLayout>

child.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="40dp"

    android:clickable="true"
    android:orientation="vertical"
    android:paddingLeft="40dp"
     >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="39dp"
        android:gravity="center_vertical" >

        <ImageView
            android:id="@+id/childImage"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_margin="5dp"
            android:background="@drawable/ic_launcher"
            android:contentDescription="@null" />

        <TextView
            android:id="@+id/textViewChild"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="Categorii"
            android:textSize="16sp"
            android:textColor="#1919A3"
            android:textStyle="bold" />
    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/white" />

</LinearLayout>

logcat:

05-19 10:18:25.180: E/AndroidRuntime(1361): FATAL EXCEPTION: main
05-19 10:18:25.180: E/AndroidRuntime(1361): Process: com.descoper.rom, PID: 1361
05-19 10:18:25.180: E/AndroidRuntime(1361): java.lang.NullPointerException
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.AbsListView.obtainView(AbsListView.java:2265)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.ListView.makeAndAddView(ListView.java:1790)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.ListView.fillDown(ListView.java:691)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.ListView.fillFromTop(ListView.java:752)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.ListView.layoutChildren(ListView.java:1630)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.AbsListView.onLayout(AbsListView.java:2091)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.View.layout(View.java:14817)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.View.layout(View.java:14817)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.View.layout(View.java:14817)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.View.layout(View.java:14817)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewGroup.layout(ViewGroup.java:4631)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1987)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1744)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5670)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.Choreographer.doCallbacks(Choreographer.java:574)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.Choreographer.doFrame(Choreographer.java:544)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.os.Handler.handleCallback(Handler.java:733)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.os.Handler.dispatchMessage(Handler.java:95)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.os.Looper.loop(Looper.java:136)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at android.app.ActivityThread.main(ActivityThread.java:5017)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at java.lang.reflect.Method.invokeNative(Native Method)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at java.lang.reflect.Method.invoke(Method.java:515)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-19 10:18:25.180: E/AndroidRuntime(1361):     at dalvik.system.NativeStart.main(Native Method)

解决方案

You are returning null from getChild() and getGroup(). You should return the corresponding group and child items from your data structures.

Also, you are returning null from getChildView() and getGroupView(). Here you should return a View that will represent the child and group Views respectively.

I suggest you read about Adapters and how they work.