명백한 널 포인터 예외
다음 코드, 주소는 정확하지만 내용이 올바르지 않습니다.
나라를 점령하고 싶다
공공 무효 inputFocus() { nation.setOnFocusChangeListener(new View.OnFocusChangeListener() { @우세하다 공공 무효 onFocusChange(보기 v, 부울 hasFocus) { 경우 (hasFocus) { // 포커스를 받았을 때의 처리 내용입니다. ImageView imageView = (ImageView) findViewById(R.id.login_diver2); imageView.setBackgroundResource(R.color.input_dvier_focus); } 또 다른 { // 포커스를 잃었을 때의 처리 내용입니다. ImageView imageView = (ImageView) findViewById(R.id.login_diver2); imageView.setBackgroundResource(R.color.input_dvier); } } });
}
그러나 실제로 내 레이아웃은 다음과 같이 작성됩니다.
<선형 레이아웃 android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp"> <텍스트뷰 android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:text="국가/지역" android:textColor="@color/loginText" android:textSize="16sp" /> <EditText android:id="@+id/log_nation" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="55dp" android:background="@null" android:hint="중국 본토 (+86)" android:singleLine="참" android:textCursorDrawable="@drawable/edit_cursor_color" android:textSize="16sp" /> </LinearLayout> <!--밑줄--> <이미지뷰 android:id="@+id/login_diver1" android:layout_width="320dp" android:layout_height="1dp" android:layout_gravity="center_horizontal" android:layout_marginTop="17dp" android:background="@color/input_dvier" />
<선형 레이아웃 android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="40dp"> <텍스트뷰 android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:text="휴대폰 번호" android:textColor="@color/loginText" android:textSize="16sp" /> <EditText android:id="@+id/log_phone" android:layout_width="200dp" android:layout_height="wrap_content" android:layout_marginLeft="55dp" 안드로이드:비밀번호="참" android:background="@null" android:hint="전화번호를 입력하세요" android:singleLine="참" android:textColorHint="@color/textColorHint" android:textCursorDrawable="@drawable/edit_cursor_color" android:textSize="16sp" tools:ignore="사용되지 않음" /> </LinearLayout> <!--밑줄--> <이미지뷰 android:id="@+id/login_diver2" android:layout_width="320dp" android:layout_height="1dp" android:layout_gravity="center_horizontal" android:layout_marginTop="17dp" android:background="@color/input_dvier" />
내 국가는 login_diver1에 해당해야 하는데 반대로 하면 비어있다고 하니 다음부터는 주의