Série da semana: Primeiros passos no React

Veja mais

Erro eclipse.

26/11/2015

1

Estou vendo esse vídeo-aula:
http://www.devmedia.com.br/testes-no-cadastro-de-pessoa-curso-de-android-criando-uma-loja-virtual-aula-46/30305

Quando aperto em cadastrar aparece:
[img]http://arquivo.devmedia.com.br/forum/imagem/464604-20151126-083343.png[/img]

Como resolver isso?
Responder

Posts

26/11/2015

Jorge Conforte

Não sei se ajuda:

11-26 10:45:09.296: E/AndroidRuntime(530): FATAL EXCEPTION: main
11-26 10:45:09.296: E/AndroidRuntime(530): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.supermecado/br.supermercado.MockActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Spinner
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.ActivityThread.access$600(ActivityThread.java:122)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.os.Looper.loop(Looper.java:137)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.ActivityThread.main(ActivityThread.java:4340)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at java.lang.reflect.Method.invokeNative(Native Method)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at java.lang.reflect.Method.invoke(Method.java:511)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at dalvik.system.NativeStart.main(Native Method)
11-26 10:45:09.296: E/AndroidRuntime(530): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Spinner
11-26 10:45:09.296: E/AndroidRuntime(530): 	at br.supermercado.MockActivity.onCreate(MockActivity.java:37)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.Activity.performCreate(Activity.java:4465)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-26 10:45:09.296: E/AndroidRuntime(530): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
11-26 10:45:09.296: E/AndroidRuntime(530): 	... 11 more
Responder

26/11/2015

Jorge Conforte

Se quiser mostro os códigos.
Responder

26/11/2015

Usuario

Post o código fazendo um favor para analisarmos!
Responder

26/11/2015

Jorge Conforte

Qual você que?
Responder

26/11/2015

Usuario

o código da MockActivity
Responder

26/11/2015

Jorge Conforte

MockActivity:
package br.supermercado;

import br.supermecado.R;
import br.supermercado.bo.MockBO;
import br.supermercado.dominio.ValidacaoMock;
import br.supermercado.dto.PessoaDTO;
import br.supermercado.util.MensagemUtil;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

public class MockActivity extends Activity {

	EditText edtNome = null;
	EditText edtEndereco = null;
	EditText edtCPF = null;
	Spinner spnProfissao = null;
	RadioGroup rgpSexo = null;
	RadioButton rbtMasc = null;
	RadioButton rbtFem = null;
	private MockBO mockBO;
	
	@Override
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_cadastro_mock);
		
		mockBO = new MockBO(this);
		
		edtNome = (EditText) findViewById(R.id.edt_nome);
		edtEndereco = (EditText) findViewById(R.id.edt_endereco);
		edtCPF = (EditText) findViewById(R.id.edt_cpf);
		spnProfissao = (Spinner) findViewById(R.id.spn_profissao);
		rgpSexo = (RadioGroup) findViewById(R.id.rgp_sexo);
		rbtMasc = (RadioButton) findViewById(R.id.rbt_masculino);
		rbtFem = (RadioButton) findViewById(R.id.rbt_feminino);
		
		ArrayAdapter adapter = new ArrayAdapter(MockActivity.this, android.R.layout.simple_spinner_item, 
				new String[] {"Professor", "Padeiro", "Jornalista", "Motorista"});
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spnProfissao.setAdapter(adapter);
	}

	public void cadastrar(View view) {
		PessoaDTO pessoaDTO = new PessoaDTO();
		pessoaDTO.setNome(edtNome.getText().toString());
		pessoaDTO.setEndereco(edtNome.getText().toString());
		pessoaDTO.setCpf(Long.parseLong(edtCPF.getText().toString()));
		pessoaDTO.setProfissao(spnProfissao.getSelectedItemPosition());
		pessoaDTO.setSexo(rbtMasc.isChecked() ? 'M' : 'F');
		
		ValidacaoMock resultado = mockBO.castrarPessoa(pessoaDTO);
		MensagemUtil.addMsg(this, resultado.getMensagem());;
		
		Intent i = new Intent(this, MockListActivity.class);
		startActivity(i);
		finish();
	}
}
Responder

26/11/2015

Usuario

Provavelmente o seu spn_profissao é um TextView.. você deve ter colocado o id errado...
Post por favor o código do xml
Responder

26/11/2015

Jorge Conforte

activity_cadastro_mock.xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/app_background"
        android:orientation="vertical"
        android:padding="@dimen/padding_large"
        tools:context=".LoginActivity" >

        <TextView
            android:id="@+id/txt_nome"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:text="Nome" />

        <EditText
            android:id="@+id/edt_nome"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:inputType="text" />

        <TextView
            android:id="@+id/txt_endereco"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:text="Endereço" />

        <EditText
            android:id="@+id/edt_endereco"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small" />

        <TextView
            android:id="@+id/txt_cpf"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:text="CPF" />

        <EditText
            android:id="@+id/edt_cpf"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:inputType="number" />

        <TextView
            android:id="@+id/txt_profissao"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:text="Profissão" />

        <Spinner
            android:id="@+id/spn_profissao"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small" />

        <TextView
            android:id="@+id/txt_sexo"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:text="Sexo" />

        <RadioGroup
            android:id="@+id/rgp_sexo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/padding_small"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/rbt_masculino"
                android:checked="true"
                android:text="Masculino" />

            <RadioButton
                android:id="@+id/rbt_feminino"
                android:text="Feminino" />
        </RadioGroup>

        <Button
            android:id="@+id/btn_cadastrar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:onClick="cadastrar"
            android:text="Cadastrar" />
    </LinearLayout>

</ScrollView>
Responder

26/11/2015

Usuario

Jorge, essa tela está Ok.. Fiz um teste aqui no meu e abriu normalmente.. o problema aconteceu quando você clica no cadastrar?
Se for, me envie o codigo e xml da MockListActivity, fazendo um favor!
Responder

26/11/2015

Jorge Conforte

Cara, olha... não sei o que fiz, mas agora conseguir abrir a tela cadastro.
Responder

26/11/2015

Jorge Conforte

Vê meu outro erro no forúm.
Responder