2
I have a problem in my project saving the fields after the changes. On the detail screen I have a change button that when I click it plays to this screen that is below: I believe the error should be in XML, because if I just play an Edittext on the screen I work. Does anyone know why ? The mistake is that he cannot cast in Edit Text.
start activity ComponentInfo{br.com.aula.primeirobanco/br.com.aula.primeirobanco.Editar}: java.lang.ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
My xml is like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<ImageView
android:id="@+id/iconeFilme"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="@drawable/ic_people_icon"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="pin" />
<TextView
android:id="@+id/alteracaoNome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="34dp"
android:layout_marginStart="34dp"
android:layout_toRightOf="@+id/iconeFilme"
android:text="@string/detalhesNome"
android:textSize="18sp" />
</LinearLayout>
But in my JAVA code it gives error:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editar);
id = (String) getIntent().getExtras().get("id");
nome = (String) getIntent().getExtras().get("nome");
sinopse = (String) getIntent().getExtras().get("sinopse");
duracao = (String) getIntent().getExtras().get("duracao");
gravarAlteracao = (Button) findViewById(R.id.botaoGravarAlteracao);
nomeAlterado = (EditText) findViewById(R.id.alteracaoNome);
sinopseAlterada = (EditText) findViewById(R.id.alteracaoSinopse);
duracaoAlterada = (EditText) findViewById(R.id.alteracaoDuracao);
I’ll attach the images for better understanding:
alteraçãoNome
is stated in the xml as a Textview and not as a Edittext– ramaral
@ramaral Even if I put the nameAltered = (Textview) findViewById(R.id.alteracaoName); it gives error and prompts to cast and switch to Edittext.
– Artur Mafezzoli Júnior
That’s because he’s (I don’t suppose I can see) declared in java as Edittext.
– ramaral
@ramaral That’s right. Many thanks again for the help.
– Artur Mafezzoli Júnior