Obrigado Nelson, funcionou graças a sua dica :)
On Friday, January 22, 2016 at 11:28:00 AM UTC-4, Bilthon wrote:
-- On Friday, January 22, 2016 at 11:28:00 AM UTC-4, Bilthon wrote:
Para identificar o problema você deve verificar o tipo da exceção. Nesse caso lendo essa linha:
ClassCastException: android.support.v7.widget.AppCompatTextView cannot be cast to android.widget.EditText
Isso me diz que o problema foi causado por um ClassCastException, específicamente você tentou fazer type casting de um TextView para um EditText. Essas duas classes não estão relacionadas na hierarquia de classes.
E de fato, você colocou em código a view com id "resultado" como sendo do tipo EditText, quando no layout ela realmente é um TextView.
Nelson
On Thursday, January 21, 2016 at 6:58:44 AM UTC-5, ricardo barbosa wrote:Pessoal bom dia,
Estou iniciando no dev do android adquiri o livro do Ricardo Lecheta e estou testando os codigos da pagina 109 mas esta me gerando os seguintes erros abaixo. Estou enviando o codigo java o layout e manifest se alguem ja passou por isso e puder me ajudar, muito Obrigado
01-21 11:51:06.411 5902-5902/corp.capsula.tratamentoeventos W/System: ClassLoader referenced unknown path: /data/app/corp.capsula. tratamentoeventos-2/lib/x86
01-21 11:51:06.595 5902-5902/corp.capsula.tratamentoeventos D/AndroidRuntime: Shutting down VM
01-21 11:51:06.602 5902-5902/corp.capsula.tratamentoeventos E/AndroidRuntime: FATAL EXCEPTION: main
Process: corp.capsula. tratamentoeventos, PID: 5902
java.lang.RuntimeException: Unable to start activity ComponentInfo{corp.capsula. tratamentoeventos/corp. capsula.tratamentoeventos. MainActivity}: java.lang.ClassCastException: android.support.v7.widget. AppCompatTextView cannot be cast to android.widget.EditText
at android.app.ActivityThread. performLaunchActivity( ActivityThread.java:2416)
at android.app.ActivityThread. handleLaunchActivity( ActivityThread.java:2476)
at android.app.ActivityThread.- wrap11(ActivityThread.java)
at android.app.ActivityThread$H. handleMessage(ActivityThread. java:1344)
at android.os.Handler. dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper. java:148)
at android.app.ActivityThread. main(ActivityThread.java:5417)
at java.lang.reflect.Method. invoke(Native Method)
at com.android.internal.os. ZygoteInit$ MethodAndArgsCaller.run( ZygoteInit.java:726)
at com.android.internal.os. ZygoteInit.main(ZygoteInit. java:616)
Caused by: java.lang.ClassCastException: android.support.v7.widget. AppCompatTextView cannot be cast to android.widget.EditText
at corp.capsula. tratamentoeventos. MainActivity.onCreate( MainActivity.java:17)
at android.app.Activity. performCreate(Activity.java: 6237)
at android.app.Instrumentation. callActivityOnCreate( Instrumentation.java:1107)
at android.app.ActivityThread. performLaunchActivity( ActivityThread.java:2369)
at android.app.ActivityThread. handleLaunchActivity( ActivityThread.java:2476)
at android.app.ActivityThread.- wrap11(ActivityThread.java)
at android.app.ActivityThread$H. handleMessage(ActivityThread. java:1344)
at android.os.Handler. dispatchMessage(Handler.java: 102)
at android.os.Looper.loop(Looper. java:148)
at android.app.ActivityThread. main(ActivityThread.java:5417)
at java.lang.reflect.Method. invoke(Native Method)
at com.android.internal.os. ZygoteInit$ MethodAndArgsCaller.run( ZygoteInit.java:726)
at com.android.internal.os. ZygoteInit.main(ZygoteInit. java:616)
01-21 11:51:08.662 5902-5902/? I/Process: Sending signal. PID: 5902 SIG: 9
MainActivity.javapackage corp.capsula.tratamentoeventos;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText textNome = (EditText) findViewById(R.id.nome);
final EditText textResultado = (EditText) findViewById(R.id.resultado);
Button botao = (Button) findViewById(R.id.enviar);
botao.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
String nome = textNome.getText().toString();
textResultado.setText("Obrigado " + nome);
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="corp.capsula.tratamentoeventos. >MainActivity"
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!"
android:id="@+id/textView" />
<Button
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button"
android:id="@+id/enviar"
android:layout_below="@+id/textView" android:layout_alignParentLeft= "true"
android:layout_alignParentStart= "true"
android:layout_marginTop="24dp" />
<EditText
android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/nome"
android:layout_below="@+id/textView" android:layout_alignParentLeft= "true"
android:layout_alignParentStart= "true"
android:inputType="none" />
<TextView
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text"
android:id="@+id/resultado"
android:layout_below="@+id/enviar" android:layout_toRightOf="@+id/nome" android:layout_toEndOf="@+id/nome" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android " package="corp.capsula.tratamentoeventos" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Desde já agradeço
Atenciosamente
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
0 comentários:
Postar um comentário