title: SurfaceView onMeasure() did not set the measured dimension by calling setMeasuredDimension()
body: <p>I have a SurfaceView. I just draw on it manually from an other Thread.</p>
  
  <p>It runs nicely. But after 10-20 minutes of running in average I get this exception:</p>
  
  <pre><code>01-14 08:51:25.000    3740-3740/com.myPackage E/AndroidRuntime﹕ FATAL EXCEPTION: main
      java.lang.IllegalStateException: onMeasure() did not set the measured dimension by calling setMeasuredDimension()
              at android.view.View.measure(View.java:15200)
              at android.widget.RelativeLayout.measureChild(RelativeLayout.java:602)
              at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:415)
              at android.view.View.measure(View.java:15195)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4823)
              at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
              at android.view.View.measure(View.java:15195)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4823)
              at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
              at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
              at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
              at android.view.View.measure(View.java:15195)
              at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4823)
              at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
              at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2340)
              at android.view.View.measure(View.java:15195)
              at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
              at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
              at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
              at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
              at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4216)
              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:4813)
              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:792)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:559)
              at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p><strong>Android Documention says:</strong>
  <br>Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.</p>
  
  <p><strong>As I think the original implementation from google is this:</strong></p>
  
  <pre><code>@Override
      protected void More ...onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int width = getDefaultSize(mRequestedWidth, widthMeasureSpec);
          int height = getDefaultSize(mRequestedHeight, heightMeasureSpec);
          setMeasuredDimension(width, height);
      }
  </code></pre>
  
  <p>I don't know what I else should I implement here.</p>
  
  <p>I think the size of the surface view never changes.</p>
  
  <p><strong>NOTE:</strong>
  <br>My SurfaceView is contained in a RelativeLayout.
  <br>The exception is called by a child, but it's a view (line 3 in the exception)</p>
  
  <p>Please help me if you know how could I solve this annoying bug.</p>
  
  <p><strong>EDIT:</strong>
  <br>In Activity's onCreate I set the size of my view (that extended form SurfaceView) from code</p>
  
  <p><strong>Answear to comment:</strong>
  <br>This is how I set some public fields for the required size:</p>
  
  <pre><code>Parameters.initialize(getResources().getDisplayMetrics().widthPixels,
                  getResources().getDisplayMetrics().heightPixels);
  </code></pre>
  
  <p>The Parameters.initialize:</p>
  
  <pre><code>public static void initialize(int screenWidth, int screenHeight){
      FIELD_WIDTH = screenWidth;
      FIELD_HEIGHT = (int)(0.92f * screenHeight);
  }
  </code></pre>
  
  <p>MyView is written in the xml.
  <br>Then I set something on it:</p>
  
  <pre><code>public class MyViewManager {
      protected MyView mMyView;
  
      public FieldPainterComp(MainActivity activity) {
          super(activity);
          initialize();
      }
  
      private void initialize(){
          mMyView= (MyView) activity.findViewById(R.id.vMyView);
          mMyView.getLayoutParams().height = Parameters.FIELD_HEIGHT;
          mMyView.getLayoutParams().width = Parameters.FIELD_WIDTH;
      }
  }
  </code></pre>
  
  <p>This whole process happens ones in the beginning.</p>
  
  <pre><code>android:screenOrientation="landscape"
  </code></pre>
  
  <p>Screen never goes dark. Game is running, and simply the exception is coming.
  <br>Should I call measure somewhere?
  <br>I don't understand why is it happaning after a long time</p>
  
  <p><strong>Some other exception that must be in connected with this:</strong></p>
  
  <pre><code>01-19 11:53:39.812  29666-31881/com.mypackage V/GAV4﹕ Thread[disconnect check,5,main]: Disconnecting due to inactivity
  01-19 11:53:39.812  29666-31881/com.mypackage V/GAV4﹕ Thread[disconnect check,5,main]: Disconnected from service
  01-19 11:57:17.732  29666-29666/com.mypackage D/AndroidRuntime﹕ Shutting down VM
  01-19 11:57:17.732  29666-29666/com.mypackage W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x420face0)
  01-19 11:57:17.812  29666-29666/com.mypackage V/GAV4﹕ Thread[main,5,main]: Tracking Exception: IllegalStateException (@View:measure:16533) {main}
  01-19 11:57:17.832  29666-29666/com.mypackage V/GAV4﹕ Thread[main,5,main]: Dispatch call queued. Dispatch will run once initialization is complete.
  01-19 12:19:27.982  29666-29670/com.mypackage I/dalvikvm﹕ threadid=3: reacting to signal 3
  01-19 12:19:28.262  29666-29670/com.mypackage I/dalvikvm﹕ Wrote stack traces to '/data/anr/traces.txt'
  01-19 12:19:32.452  29666-29666/com.mypackage A/libc﹕ Fatal signal 6 (SIGABRT) at 0x0000025a (code=0), thread 29666 (ames.adaptation)
  </code></pre>
  
  <p>The GAV -is the Google Analytics stuff.</p>
  
  <p>I launched an other question about the ANR: <a href="https://stackoverflow.com/questions/27990089/anr-with-3-threads-using-locks">ANR with 3 threads - using locks</a></p>