Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on click group item #28

Closed
Collosteam opened this issue Sep 28, 2014 · 5 comments
Closed

Exception on click group item #28

Collosteam opened this issue Sep 28, 2014 · 5 comments

Comments

@Collosteam
Copy link

On Nexus 4 (Android 4.4.4) all work well, but on (Android 4.1.1) after lick on group item, application crashed with stacktrace:

FATAL EXCEPTION: main
java.lang.NullPointerException
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:495)
at android.view.View.measure(View.java:15172)
at com.idunnololz.widgets.AnimatedExpandableListView$AnimatedExpandableListAdapter.getChildView(AnimatedExpandableListView.java:386)
at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
at android.widget.AbsListView.obtainView(AbsListView.java:2267)
at android.widget.ListView.makeAndAddView(ListView.java:1769)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillSpecific(ListView.java:1330)
at android.widget.ListView.layoutChildren(ListView.java:1600)
at android.widget.AbsListView.onLayout(AbsListView.java:2102)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
at android.view.View.layout(View.java:13754)
at android.view.ViewGroup.layout(ViewGroup.java:4362)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1866)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1687)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

@idunnololz
Copy link
Owner

Can you please post your expandablelistview structure (like layout for child and group views and how many types of child and or group views) ? Thanks

@idunnololz
Copy link
Owner

If you are testing using vanilla Android then line 495 in the relative layout source is
if (mLayoutParams.height >= 0) {
Which must mean that the layout params of a Relative Layout is null.

@Collosteam
Copy link
Author

I'm used simple adapter
public class ExpListAdapter extends AnimatedExpandableListView.AnimatedExpandableListAdapter {

Context context;
ArrayList<String> groups;
ArrayList<ArrayList<String>> titles;

public ExpListAdapter(Context context, ArrayList<String> groups, ArrayList<ArrayList<String>> titles) {
    this.context = context;
    this.groups = groups;
    this.titles = titles;

}

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

@Override
public Object getGroup(int groupPosition) {
    return titles.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return titles.get(groupPosition).get(childPosition);
}

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

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

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

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.start_parent, null);
    }
      TextView textGroup = (TextView) convertView.findViewById(R.id.tv_parent_size);
    textGroup.setText(groups.get(groupPosition));
    TextView textGroupnum = (TextView) convertView.findViewById(R.id.tv_parent_numbet);
    textGroupnum.setText(String.valueOf(groupPosition + 1));
    return convertView;
}

@Override
public View getRealChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.start_childer, null);
    }
    TextView textChild = (TextView) convertView.findViewById(R.id.tv_children_name);
    textChild.setText(titles.get(groupPosition).get(childPosition));
    return convertView;
}
@Override
public int getRealChildrenCount(int groupPosition) {
    return titles.get(groupPosition).size();
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

}

In my expandable list, I use one view type for group and and one for child view

In activie I'm use next code:
// In order to show animations, we need to use a custom click handler
// for our ExpandableListView.

    listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            // We call collapseGroupWithAnimation(int) and
            // expandGroupWithAnimation(int) to animate group
            // expansion/collapse.
            if (listView.isGroupExpanded(groupPosition)) {
                listView.collapseGroupWithAnimation(groupPosition);
            } else {
                listView.expandGroupWithAnimation(groupPosition);
            }
            return true;
        }

    })

@idunnololz
Copy link
Owner

Instead of using LayoutInflater.inflate(int layoutId, ViewGroup parent) try using LayoutInflater.inflate(int layoutId, ViewGroup root, boolean attachToRoot).

So replace inflater.inflate(R.layout.start_parent, null); with inflater.inflate(R.layout.start_parent, parent, false); and inflater.inflate(R.layout.start_childer, null); with inflater.inflate(R.layout.start_childer, parent, false);

@Collosteam
Copy link
Author

Thank you very much! Did not pay attention(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants