适配器错误:NullPointerException:尝试调用虚方法' int android.view.View.getImportantForAccessibility()

时间:2017-02-25 23:10:54

标签: android nullpointerexception listadapter getview

我无法找到导致此空指针的内容,我为子节点和父节点返回了rowview。我通常认为它是由某些视图返回null引起的,但在这种情况下我无法找到错误。提前感谢您的答案

我的适配器代码

public class CorrAdapter extends BaseExpandableListAdapter {

private List<Correlativa> materias;
private LayoutInflater inflater = null;

public CorrAdapter(Context context, List<Correlativa> materias) {
    this.materias = materias;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

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

@Override
public int getChildrenCount(int i) {
    return materias.get(i).getCorrelativas().size();
}

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

@Override
public Object getChild(int i, int i1) {
    return null;
}

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

@Override
public long getChildId(int i, int i1) {
    return 0;
}

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

@Override
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {


    ParentHolder parentHolder;
    View rowView = view;

    if (rowView == null) {

        rowView = inflater.inflate(R.layout.expandable_parent, viewGroup, false);
        parentHolder = new ParentHolder();

        parentHolder.tvMateria = (TextView) rowView.findViewById(R.id.tvCorrMateria);
        parentHolder.tvEstado = (TextView) rowView.findViewById(R.id.tvCorrEstado);

        rowView.setTag(parentHolder);
    } else {

        parentHolder = (ParentHolder) view.getTag();

    }



    parentHolder.tvMateria.setText(materias.get(i).getNombreMateria());

    String estadoMateria = materias.get(i).getCorrelativas().get(0);

    if(estadoMateria.equals("Puede cursar") || estadoMateria.equals("Puede inscribirse")) {
        parentHolder.tvEstado.setText(estadoMateria);
        return null;
    }

    else
        parentHolder.tvEstado.setText("No cumple correlativas");


    return rowView;
}

@Override
public View getChildView(int i, int i1, boolean b, View view, ViewGroup viewGroup) {

    View rowView = view;
    ChildHolder childHolder;

    if (rowView == null) {

        rowView = inflater.inflate(R.layout.expandable_child, viewGroup, false);
        childHolder = new ChildHolder();

        childHolder.tvCorr = (TextView) rowView.findViewById(R.id.tvCorr2);
        rowView.setTag(childHolder);

    } else {

        childHolder = (ChildHolder) rowView.getTag();

    }

    childHolder.tvCorr.setText(materias.get(i).getCorrelativas().get(i1));

    return rowView;
}

@Override
public boolean isChildSelectable(int i, int i1) {
    return false;
}

private static class ParentHolder {
    TextView tvMateria, tvEstado;
}

private static class ChildHolder {
    TextView tvCorr;
}

Logcat错误

E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: com.technocell.myapplication, PID: 27851
                                                                          java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
                                                                              at android.widget.AbsListView.obtainView(AbsListView.java:2388)
                                                                              at android.widget.ListView.measureHeightOfChildren(ListView.java:1326)
                                                                              at android.widget.ListView.onMeasure(ListView.java:1233)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                                                                              at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
                                                                              at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:786)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                              at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
                                                                              at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
                                                                              at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                              at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                              at com.android.internal.policy.DecorView.onMeasure(DecorView.java:689)
                                                                              at android.view.View.measure(View.java:19857)
                                                                              at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2275)
                                                                              at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1366)
                                                                              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1619)
                                                                              at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
                                                                              at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6338)
                                                                              at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
                                                                              at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                              at android.view.Choreographer.doFrame(Choreographer.java:621)
                                                                              at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
                                                                              at android.os.Handler.handleCallback(Handler.java:751)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

1 个答案:

答案 0 :(得分:0)

在方法ValueError: stat: embedded null character in path中,您有以下几行:

getGroupView

我认为这有时会导致if(estadoMateria.equals("Puede cursar") || estadoMateria.equals("Puede inscribirse")) { parentHolder.tvEstado.setText(estadoMateria); return null; } 返回。修复如下:

null