나는이 프로그래밍이 어리석은 것처럼 보일 때 안드로이드 프로그래밍에 익숙하지 않으므로 나를 용서해 주었다. Android 용 계산기를 개발 중입니다. 그래서 약 20 개의 버튼과 텍스트 필드가 있습니다. 버튼을 누를 때마다 사용자가 입력 한 내용을 알 수 있도록 텍스트 필드를 업데이트합니다.안드로이드에서 텍스트 설정
그러나 텍스트 필드를 업데이트하면 응용 프로그램이 충돌합니다.
updateExpression은 버튼을 누를 때 호출되는 메서드입니다.
public void updateExpression (View v)
{
Log.d("string", "updateExpression Called");
EditText text = (EditText) findViewById(R.id.name);
text.setText("HELLO EVERYONE");
}
버튼의 .XML 파일은 다음과 같습니다
<Button
android:id="@+id/Button03"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/name"
android:layout_below="@+id/name"
android:onClick="updateExpression"
android:text="C" />
// goes on for 20 buttons with different ids and text
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:text="@string/edit_message"
android:layout_height="33dp"
android:textColor="@color/opaque_red"/>
</RelativeLayout>
마지막으로 로그 캣은 문자열 데이터 "호출 updateExpression"을 가지고있다. 그러나 그 직후에 충돌이 발생합니다. 오류는 AndroidRuntime Fatal Exception main 태그를가집니다. 이 후에는 더 많은 오류가 있습니다. java.lang.classCatException : 관련 한
는에 의해 발생 (나를 따라가) android.widget.TextView 이 android.widget.EditText
친절하게 도움으로 캐스팅 할 수 없습니다.
감사합니다. 당신의 XML로
TextView text = (TextView) findViewById (R.id.name); 오류를 제공합니다 : TextView는 유형으로 해석 될 수 없습니다. –
eclipse를 사용하는 경우 + shift + o를 사용하여 가져 오기를 추가하십시오. – wtsang02
가져와야합니다. Press ctrl + shift + O –