如何理解堆栈跟踪以从android崩溃报告中找到崩溃的原因

时间:2013-12-19 06:57:34

标签: android expandablelistview crash-reports

以下是我从我的应用程序收到的用于alpha测试的崩溃报告。任何人都可以说明我应该怎么读这个?它说NullPointerException,但在哪里?我有一个可扩展的列表视图,是因为它获取一个空对象绑定到列表项? 这是似乎抛出NPE的方法:

@Override
public View getChildView(int parent, int child, boolean arg2,
        View convertView, ViewGroup container) {
    ViewHolder mHolder;
    CategoryEntity childEntity = childlist.get(parent).get(child);
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.category_row, container,
                false);
        mHolder = new ViewHolder();
        mHolder.cateogoryname = (TextView) convertView
                .findViewById(R.id.textView);
        mHolder.imageView = (ImageView) convertView
                .findViewById(R.id.imageView1);
        convertView.setTag(mHolder);
    } else {
        mHolder = (ViewHolder) convertView.getTag();
    }
    if (childEntity != null) {
        String replace = childEntity.getSq_displayName().equals("") ? childEntity
                .getCatname() : childEntity.getSq_displayName().replace(
                "<br>", "");

        Spannable span = new SpannableString(replace);
        switch (childEntity.getSq_cat_id()) {
        case 1:
            mHolder.imageView.setImageResource(R.drawable.ic_food);
            break;
        case 2:
            mHolder.imageView.setImageResource(R.drawable.ic_home);
            break;
        case 3:
            mHolder.imageView.setImageResource(R.drawable.ic_apparels);

            mHolder.cateogoryname.setText(replace);
            break;
        case 4:
            mHolder.imageView.setImageResource(R.drawable.ic_beauty);

            break;
        case 5:
            mHolder.imageView.setImageResource(R.drawable.ic_electronics);
            break;
        case 6:
            mHolder.imageView.setImageResource(R.drawable.ic_mobile);

            break;

        }
        span.setSpan(new ForegroundColorSpan(Color.rgb(0, 161, 220)), 0, 1,
                Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
        span.setSpan(new android.text.style.StyleSpan(
                android.graphics.Typeface.BOLD), 0, 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        span.setSpan(new AbsoluteSizeSpan(18, true), 0, 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mHolder.cateogoryname.setGravity(GravityCompat.START);

        mHolder.cateogoryname.setText(span);
    }

    return convertView;
}

这是堆栈跟踪:

java.lang.NullPointerException
at com.application.app.entity.e.getChildView(Unknown Source)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
at android.widget.AbsListView.obtainView(AbsListView.java:2271)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1269)
at android.widget.ListView.onMeasure(ListView.java:1181)
at android.view.View.measure(View.java:15323)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4924)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1421)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:698)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:579)
at android.view.View.measure(View.java:15323)
at android.support.v4.widget.DrawerLayout.onMeasure(Unknown Source)
at android.view.View.measure(View.java:15323)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4924)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:315)
at android.view.View.measure(View.java:15323)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4924)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1421)

1 个答案:

答案 0 :(得分:0)

这里最相关的一行是com.application.app.entity.e.getChildView

据说这条线上有一个java.lang.NullPointerException。也许您正在尝试访问尚未初始化的视图(即它为空)。