Android アプリケーションで次のコードを呼び出しています。古い Samsung Dart (api < 13) で実行すると、以下に示すように NullPointer 例外が発生します。
NullPointer を取得している行ではなく、その上の 4 行でコードが機能している特定の理由はありますか?
@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void adjustSize() {
int width, height;
Display display = getWindowManager().getDefaultDisplay();
if (android.os.Build.VERSION.SDK_INT >= 13) {
Point size = new Point();
display.getSize(size);
width = size.x;
height = size.y;
} else {
width = display.getWidth(); // deprecated
height = display.getHeight(); // deprecated
}
ImageView counties = (ImageView) findViewById(R.id.btnCounties);
ImageView members = (ImageView) findViewById(R.id.btnMembers);
ImageView webLink = (ImageView) findViewById(R.id.btnWebLink);
ImageView logo = (ImageView) findViewById(R.id.logo);
// Calculate image sizes
if (height > width) {
counties.getLayoutParams().height = (int) (width / 2.5);
counties.getLayoutParams().width = (int) (width / 2.5);
members.getLayoutParams().height = (int) (width / 2.5);
members.getLayoutParams().width = (int) (width / 2.5);
webLink.getLayoutParams().height = (int) ((width / 2.4) / 3.5); // Null pointer error
webLink.getLayoutParams().width = (int) (width / 2.4);
logo.getLayoutParams().height = (int) (height / 6);
logo.getLayoutParams().width = width;
} else {
counties.getLayoutParams().height = (int) (height / 2.5);
counties.getLayoutParams().width = (int) (height / 2.5);
members.getLayoutParams().height = (int) (height / 2.5);
members.getLayoutParams().width = (int) (height / 2.5);
}
}