我有一个奇怪的问题。
使用此代码,在“错误5”之前尝试制作新的LayoutParams时会崩溃。
getScreenWidthAndHeight();
Log.d("Error", "1");
eField = (EditText)findViewById(R.id.emailField);
Log.d("Error", "2");
pField = (EditText)findViewById(R.id.passwordField);
Log.d("Error", "3");
signInButton = (Button)findViewById(R.id.singInButton);
Log.d("Error", "4");
RelativeLayout.LayoutParams lParamsForEField = new RelativeLayout.LayoutParams(eField.getWidth(), eField.getHeight());
Log.d("Error", "5");
RelativeLayout.LayoutParams lParamsForPField = (LayoutParams) pField.getLayoutParams();
Log.d("Error", "6");
RelativeLayout.LayoutParams lParamsForSignInButton = (LayoutParams) signInButton.getLayoutParams();
CLOSED
引起:java.lang.NullPointerException
问题在于在为内容视图设置布局之前尝试查找元素。