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

java.lang.IndexOutOfBoundsException CardWithList inside of a CardListView #553

Open
delkant opened this issue Sep 3, 2016 · 0 comments
Open

Comments

@delkant
Copy link

delkant commented Sep 3, 2016

Hello!
I am having this exception every time I try to scroll back to the top. Is this a bug? or maybe I am just doing something wrong. can you please advice? Thanks!

compileSdkVersion 24
Version:

compile 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.1.0'

here is the source for the RecyclerView loader..

public class CardsRecyclerViewFragment extends BaseNativeListFragment {

    CardArrayRecyclerViewAdapter mCardArrayAdapter;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return  inflater.inflate(R.layout.demo_fragment_native_recyclerview, container, false);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        hideList(false);

        //Set the arrayAdapter
        ArrayList<Card> cards = new ArrayList<Card>();

        mCardArrayAdapter = new CardArrayRecyclerViewAdapter(getActivity(), cards);

        //Staggered grid view
        CardRecyclerView mRecyclerView = (CardRecyclerView) getActivity().findViewById(R.id.carddemo_recyclerview);
        mRecyclerView.setHasFixedSize(false);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

        //Set the empty view
        if (mRecyclerView != null) {
            mRecyclerView.setAdapter(mCardArrayAdapter);
        }

        //Load cards
        new LoaderAsyncTask().execute();
    }

    //-------------------------------------------------------------------------------------------------------------
    // Images loader
    //-------------------------------------------------------------------------------------------------------------
    /**
     * Async Task to elaborate images
     */
    class LoaderAsyncTask extends AsyncTask<Void, Void, ArrayList<Card>> {

        LoaderAsyncTask() {
        }

        @Override
        protected ArrayList<Card> doInBackground(Void... params) {
            //elaborate images
            //SystemClock.sleep(1000); //delay to simulate download, don't use it in a real app
            if (isAdded()) {
                ArrayList<Card> cards = initCard();
                return cards;
            }else
                return null;
        }

        @Override
        protected void onPostExecute(ArrayList<Card> cards) {
            //Update the adapter
            updateAdapter(cards);
            displayList();
        }
    }

    /**
     * This method builds a simple list of cards
     */
    private ArrayList<Card> initCard() {

        //Init an array of Cards
        ArrayList<Card> cards = new ArrayList<Card>();
        for (int i = 0; i < 50; i++) {
            CardWithListTest card = new CardWithListTest(getActivity());
            card.init();
            cards.add(card);
        }

        return cards;
    }

    /**
     * Update the adapter
     */
    private void updateAdapter(ArrayList<Card> cards) {
        if (cards != null) {
            mCardArrayAdapter.addAll(cards);
        }
    }


} 

This is the code for the CardWithList.


public class CardWithListTest extends CardWithList {

    public CardInvoiceWithOrders(Context context) {
        super(context);
    }

    @Override
    protected CardHeader initCardHeader() {
        //Add Header
        CardHeader header = new CardHeader(getContext(), R.layout.card_invoice_with_orders_header);
        header.setTitle("M-1 | {faw_user} Rodrigo Del canto"); //should use strings.xml
        return header;
    }

    @Override
    protected void initCard() {
        //Set the whole card as swipeable
        setSwipeable(false);
        setOnSwipeListener(new OnSwipeListener() {
            @Override
            public void onSwipe(Card card) {
                Toast.makeText(getContext(), "Swipe on " + card.getCardHeader().getTitle(), Toast.LENGTH_SHORT).show();
            }
        });
    }


    @Override
    protected List<ListObject> initChildren() {

        //Init the list
        List<ListObject> mObjects = new ArrayList<ListObject>();

        //Add an object to the list
        Order s1 = new Order(this);
        s1.code = "P-1-1";
        s1.description = "2Ham, 3Cerv, 4Gas, 2Mila";
        s1.drinks = 3;
        s1.kitchen = 1;
        mObjects.add(s1);

        Order s2 = new Order(this);
        s2.code = "P-1-2";
        s2.description = "2Ham, 4Gas, 2Croq,2pasta";
        s2.drinks = 1;
        s2.kitchen = 4;
        mObjects.add(s2);

        Order s3 = new Order(this);
        s3.code = "P-1-3";
        s3.description = "4Emp, 3Cerv, 4Gas, 2Ensa";
        s3.drinks = 2;
        s3.kitchen = 2;
        mObjects.add(s3);

        Order s4 = new Order(this);
        s4.code = "P-1-4";
        s4.description = "2Ensa, 2Wis, 3Cerv, 4Agua";
        s4.drinks = 2;
        s4.kitchen = 2;
        mObjects.add(s4);

        return mObjects;
    }

    @Override
    public View setupChildView(int childPosition, ListObject object, View convertView, ViewGroup parent) {

        //Setup the ui elements inside the item
        TextView textViewCode = (TextView) convertView.findViewById(R.id.textViewCode);
        TextView textViewDesc = (TextView) convertView.findViewById(R.id.textViewDesc);
        TextView textViewDrinks = (TextView) convertView.findViewById(R.id.textViewDrinks);
        TextView textViewKitchen = (TextView) convertView.findViewById(R.id.textViewKitchen);

        //Retrieve the values from the object
        Order order = (Order) object;
        textViewCode.setText(order.code);
        textViewDesc.setText( order.description);
        textViewDrinks.setText(order.drinks);
        textViewKitchen.setText( order.kitchen);
        return convertView;
    }

    @Override
    public int getChildLayoutId() {
        return R.layout.card_invoice_with_orders_inner_main;
    }


    // -------------------------------------------------------------
    // Weather Object
    // -------------------------------------------------------------

    public class Order extends DefaultListObject {

        public String code;
        public String description;
        public int drinks;
        public int kitchen;

        public Order(Card parentCard) {
            super(parentCard);
            init();
        }

        private void init() {
            //OnClick Listener
            setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(LinearListView parent, View view, int position, ListObject object) {
                    Toast.makeText(getContext(), "Click on " + getObjectId(), Toast.LENGTH_SHORT).show();
                }
            });
        }

        @Override
        public String getObjectId() {
            return code;
        }
    }

}

Here is the runtime Exception.

09-03 04:38:44.985 13217-13217/com.test.cardList E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.test.cardList, PID: 13217
                                                                            java.lang.IndexOutOfBoundsException
                                                                                at android.graphics.Canvas.drawTextRun(Canvas.java:1802)
                                                                                at android.text.TextLine.drawTextRun(TextLine.java:991)
                                                                                at android.text.TextLine.handleText(TextLine.java:789)
                                                                                at android.text.TextLine.handleRun(TextLine.java:960)
                                                                                at android.text.TextLine.drawRun(TextLine.java:398)
                                                                                at android.text.TextLine.draw(TextLine.java:196)
                                                                                at android.text.Layout.drawText(Layout.java:413)
                                                                                at android.widget.Editor.drawHardwareAccelerated(Editor.java:1585)
                                                                                at android.widget.Editor.onDraw(Editor.java:1507)
                                                                                at android.widget.TextView.onDraw(TextView.java:5715)
                                                                                at android.view.View.draw(View.java:16178)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15174)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15169)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15169)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15169)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15169)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.draw(View.java:16181)
                                                                                at it.gmariotti.cardslib.library.view.ForegroundLinearLayout.draw(ForegroundLinearLayout.java:197)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15174)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15169)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.draw(View.java:16181)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15174)
                                                                                at android.view.View.draw(View.java:15948)
                                                                                at android.view.ViewGroup.drawChild(ViewGroup.java:3609)
                                                                                at android.support.v7.widget.RecyclerView.drawChild(RecyclerView.java:4134)
                                                                                at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3399)
                                                                                at android.view.View.draw(View.java:16181)
                                                                                at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3543)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15174)
                                                                                at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
                                                                                at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15134)
                                                                                at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
                                                                                at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15134)
                                                                                at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
                                                                                at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15134)
                                                                                at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
                                                                                at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15134)
                                                                                at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3593)
                                                                                at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3573)
                                                                                at android.view.View.updateDisplayListIfDirty(View.java:15134)
                                                                                at android.view.ViewGroup.recreateChildDisplayList(Vie
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

1 participant