classcastexception:android.Widget.EditText cannot be cast to android.view.viewgroup -


here layout file. when try run android app on emulator crashes , in logcat logcat error :

classcastexception: android.widget.edittext cannot cast  android.view.viewgroup.  

i searched on google error , found out occurs when view not closed. checked , didnt find mistakes.any , advice appreciated. thank you.

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/relativelayout1"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"    tools:context="com.example.form_app.mainactivity"    tools:ignore="mergerootframe" >  <textview     android:id="@+id/textview1"     android:layout_width="match_parent"     android:layout_height="44dp"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:text="                 information form"     android:textappearance="?android:attr/textappearancemedium" />  <textview     android:id="@+id/textview2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/textview1"     android:layout_margintop="24dp"     android:text="name"     android:textappearance="?android:attr/textappearancemedium" />  <textview     android:id="@+id/textview3"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/name"     android:layout_margintop="33dp"     android:text="age"     android:textappearance="?android:attr/textappearancemedium" />  <button     android:id="@+id/submit"     style="?android:attr/buttonstylesmall"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/textview5"     android:layout_margintop="28dp"     android:text="submit" />  <edittext     android:id="@+id/name"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/textview2"     android:layout_alignparentright="true"     android:layout_marginright="18dp"     android:ems="10"     android:inputtype="textpersonname" />     <edittext     android:id="@+id/age"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/textview3"     android:layout_alignleft="@+id/name"     android:layout_aligntop="@+id/textview3"     android:ems="10"     android:inputtype="number" />  <spinner     android:id="@+id/gender"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/textview4"     android:layout_alignleft="@+id/age"     android:layout_aligntop="@+id/textview4" />  <textview     android:id="@+id/textview5"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/textview4"     android:layout_margintop="32dp"     android:text="address"     android:textappearance="?android:attr/textappearancemedium" />  <edittext     android:id="@+id/address"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignbottom="@+id/submit"     android:layout_alignparentright="true"     android:layout_aligntop="@+id/textview5"     android:ems="10"     android:inputtype="textmultiline"      />  <textview     android:id="@+id/textview4"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_below="@+id/age"     android:layout_margintop="22dp"     android:text="gender"     android:textappearance="?android:attr/textappearancemedium" /> </relativelayout> 

and here code initialise these views..

public class mainactivity extends actionbaractivity implements onclicklistener {  edittext name,age,address; button submit; spinner gender; arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(4); @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      if (savedinstancestate == null) {         getsupportfragmentmanager().begintransaction()                 .add(r.id.age, new placeholderfragment()).commit();     }     //actual code      initialise(); }  private void initialise() {     // todo auto-generated method stub     name=(edittext)findviewbyid(r.id.name);     age=(edittext)findviewbyid(r.id.age);     address=(edittext)findviewbyid(r.id.address);     submit=(button)findviewbyid(r.id.submit);     gender=(spinner)findviewbyid(r.id.gender);     submit.setonclicklistener(this);     arrayadapter<charsequence> adapter =   arrayadapter.createfromresource(this,  r.array.gender, android.r.layout.simple_spinner_item);     adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);     gender.setadapter(adapter); } 

}

try shutting down , restarting ide , emulator. issue seems pretty common:

android classcastexception radiogroup radiobutton

android.widget.radiobutton cannot cast android.widget.spinner

classcastexception: android.widget.edittext

these issues resolved 1 or more of following:

  • clean , build project
  • restart ide
  • restart emulator

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -