ImageView getLayoutParams() returns null

Because your imageview is on air, you didn't put it on screen. So it has not have any layout params or any size.

If you want to set image's height to 50 you may consider to set layoutParams of this view... You can set layoutParams' height as 50. So it'll do what you seek.

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 50));
 img.setLayoutParams(lp);

these lines will set your image's height to 50, but don't forget i'm assuming that your parent view as linear layout, if it's not, then you should use its layoutparams.