illegalargumentException

Issue #14 invalid
siddharth shah created an issue

java.lang.IllegalArgumentException: width and height must be > 0
at com.echo.holographlibrary.BarGraph.onDraw(BarGraph.java:80) fullImage = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888);

Comments (5)

  1. Daniel Nadeau repo owner

    You have most likely specified a negative value, or the layout for the BarGraph is 0 height or width.

  2. Maciej Donajski

    I have exactly the same issue if BarGraph is inside HorizontallScrollView. Width and height of parent view is for sure > 0 and width and height for BarGraph is:

     android:layout_width="300dp"
     android:layout_height="200dp"
    

    getWidth() in onDraw() returns 0.

  3. Maciej Donajski

    I will try to send you some pull request later but just for your consideration I think problem is when

    MeasureSpec.UNSPECIFIED
    

    is passed to onMeasure() of View, then no specific width/height is forced by parent and 0 is assigned. In case of unspecified width or height some default (optimal for display) sizes should be passed to setMeasuredDimensions(). Quick solution for width (which is my problem in HorizontalScrollView):

     @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    
            if(widthMeasureSpec == MeasureSpec.UNSPECIFIED) {
                int width = mBars.size() * (int)mContext.getResources().getDisplayMetrics().density * OPT_COL_WIDTH;
                width +=  (mBars.size() - 1) * (int)mContext.getResources().getDisplayMetrics().density * OPT_PADDING_WIDTH;
                setMeasuredDimension(width, getMeasuredHeight());
            }
    
        }
    

    Hope it will help. Excellent lib BTW :).

  4. Log in to comment