title: Android ClassCastException in GridLayout
body: <p>i try to add gridview to gridlayout in android but it shows classcastexception what is the problem and how to solve the exception</p>
  
  <pre><code>03-22 22:47:24.937: E/AndroidRuntime(1564): FATAL EXCEPTION: main
  03-22 22:47:24.937: E/AndroidRuntime(1564): java.lang.ClassCastException: android.widget.AbsListView$LayoutParams cannot be cast to android.widget.GridLayout$LayoutParams
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.GridLayout.getLayoutParams1(GridLayout.java:729)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.GridLayout.validateLayoutParams(GridLayout.java:663)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.GridLayout.getLayoutParams(GridLayout.java:734)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.GridLayout.measureChildrenWithMargins(GridLayout.java:866)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.GridLayout.onMeasure(GridLayout.java:894)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.View.measure(View.java:12723)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.View.measure(View.java:12723)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.View.measure(View.java:12723)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:812)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.View.measure(View.java:12723)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.View.measure(View.java:12723)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.os.Handler.dispatchMessage(Handler.java:99)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.os.Looper.loop(Looper.java:137)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at android.app.ActivityThread.main(ActivityThread.java:4424)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at java.lang.reflect.Method.invoke(Method.java:511)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
  03-22 22:47:24.937: E/AndroidRuntime(1564):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>@Override
      protected void onCreate(Bundle savedInstanceState) {</p>
  
  <pre><code>    super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_puzzle);
  
      // Disable all animations
      getWindow().setWindowAnimations(0);
  
      // Get grid size/difficulty, default 4x4
      SharedPreferences prefs = getSharedPreferences(PREFS_NAME, 0);
      GRID_SIZE = prefs.getInt("gridSize", 4);
  
      // get image ID/path from intent
      Integer imageID = getIntent().getIntExtra("image", 0);
  
      try {
          this.imageGrid = createGrid();
      } catch (IOException e) {
          e.printStackTrace();
      }
      gridlay = (GridLayout)this.findViewById(R.id.grid_layout);
      gridlay.addView(this.imageGrid);
  
  
  }
  </code></pre>
  
  <p>private GridView createGrid() throws IOException {
          Bitmap puzzleImage = null;</p>
  
  <pre><code>    puzzleImage = loadScaledImage();
      int imageWidth = puzzleImage.getWidth();
      int imageHeight = puzzleImage.getHeight();
  
      GridView grid = new GridView(this);
      grid.setLayoutParams(new GridView.LayoutParams(imageWidth, imageHeight));
  
      grid.setNumColumns(this.GRID_SIZE);
      grid.setColumnWidth(imageWidth/this.GRID_SIZE);
  
      grid.setAdapter(new ImageAdapter(this, this.GRID_SIZE, puzzleImage));
      puzzleImage.recycle();
  
      grid.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              ImageAdapter adapter = (ImageAdapter)parent.getAdapter();
              int[] tileOrder = adapter.getTileOrder();
              int blankTile = adapter.BLANK_TILE_ID;
  
              if (attemptMove(tileOrder, position, blankTile)) {
                  adapter.notifyDataSetChanged();
              }
  
              checkPuzzleSolved(tileOrder);
          }
      });
  
      return grid;
  }
  </code></pre>