public class AdminMainActivity extends Activity {
private String row = "";
private String column = "";
private GridLayout gl;
int totalRoom = 0, floor= 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity_layout);
Intent intent = getIntent();
row = intent.getStringExtra("row");
column = intent.getStringExtra("column");
Log.d("gngngn", row);
Log.d("gngngn", column);
gl = new GridLayout(this);
gl.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
gl = (GridLayout)findViewById(R.id.gdl_admin_room);
gl.setRowCount(Integer.parseInt(row));
gl.setColumnCount(Integer.parseInt(column));
totalRoom = Integer.parseInt(row) * Integer.parseInt(column);
Button btn[] = new Button[totalRoom];
floor = 100;
for(int i = 0; i < totalRoom; i++){
btn[i] = new Button(this);
if(i / Integer.parseInt(column) == 0)
floor += 100;
btn[i].setText(floor + i + "호");
btn[i].setId(i);
}
}
다른 Activity에서 정수값을 받아와서 Integer로 변환하여 집어넣는데 자꾸 NullPointerException이 납니다...
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.GridLayout.setRowCount(int)' on a null object reference
at org.springframework.android.basicauth.AdminMainActivity.onCreate(AdminMainActivity.java:54)
Log를 찍어보면 값은 정상적으로 잘 들어옵니다..
제가 Layout을 Java Code로는 처음짜봐서 ㅠㅠ.... 경험이 풍부하신 선배님들의 조언을 구합니다...