java.lang.ClassCastException: android.widget.TextView -
i've layout xml, named pagina.xml:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical" > <textview android:id="@+id/descrizione" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_alignparentright="true" android:layout_alignparenttop="true" android:text="large text" android:textappearance="?android:attr/textappearancelarge" /> <button android:id="@+id/scelta1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_centerhorizontal="true" android:text="button" /> <button android:id="@+id/scelta3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/scelta1" android:layout_alignleft="@+id/scelta1" android:layout_marginbottom="16dp" android:text="button" /> <button android:id="@+id/scelta2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/scelta3" android:layout_alignleft="@+id/scelta3" android:layout_marginbottom="18dp" android:text="button" /> </relativelayout>
i want write description of element, when assign variable textview element, emulator crashes. code:
public int posizione; public string stanza; public string[] azioni; public int[] vai; public xmlpullparser xpp; public edittext descr; public button scelta_1, scelta_2, scelta_3; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.pagina); try { carica_stanza(posizione); } catch (filenotfoundexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (xmlpullparserexception e) { // todo auto-generated catch block e.printstacktrace(); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } descr = (edittext) this.findviewbyid(r.id.descrizione); scelta_1= (button) this.findviewbyid(r.id.scelta1); scelta_2= (button) this.findviewbyid(r.id.scelta2); scelta_3= (button) this.findviewbyid(r.id.scelta3); }
help me understand!
try
public textview descr; // ... descr = (textview) this.findviewbyid(r.id.descrizione);
instead of
public edittext descr; // ... descr = (edittext) this.findviewbyid(r.id.descrizione);
you using textview
in xml layout. tried cast object edittext
what going use? if want text editable need change component edittext
in xml , in class.
- textview - prints text
- edittext - lets edit text in program
Comments
Post a Comment