0

I am trying to create whiteboard type application using fragments. But, I am having problem in height whenever fragments called height is always zero but this code is working perfect in activities. When onSizeChanged function called height is always 0. Please see the code and error below

getting this error

FATAL EXCEPTION: main
          Process: com.example.ebmacs.vickyy.kids, PID: 5781
          java.lang.IllegalArgumentException: width and height must be > 0
              at android.graphics.Bitmap.createBitmap(Bitmap.java:829)
              at android.graphics.Bitmap.createBitmap(Bitmap.java:808)
              at android.graphics.Bitmap.createBitmap(Bitmap.java:775)
              at com.example.ebmacs.vickyy.kids.Classes.PaintView.onSizeChanged(PaintView.java:82)
              at android.view.View.sizeChange(View.java:16748)
              at android.view.View.setFrame(View.java:16710)
              at android.view.View.layout(View.java:16627)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
              at android.widget.ScrollView.onLayout(ScrollView.java:1525)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
              at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1732)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1497)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
              at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
              at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
              at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
              at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
              at android.view.View.layout(View.java:16630)
              at android.view.ViewGroup.layout(ViewGroup.java:5437)
              at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
            at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1

this is code where i get error

 @Override
public void onSizeChanged(int widthContentView, int heightContentView, int oldWidth, int oldHeight) {
    super.onSizeChanged(widthContentView, heightContentView, oldWidth, oldHeight);
    this.bitmap = Bitmap.createBitmap(widthContentView,heightContentView, Bitmap.Config.ARGB_8888);
    this.canvas = new Canvas(bitmap);
}
Muhammad Waqas
  • 64
  • 1
  • 10

0 Answers0