java.lang.ClassCastException: android.widget.TextView. Por que estou obtendo isso?

Por algum motivo, recebo um erro ClassCastException. Eu realmente não sei por quê.

Agradecemos antecipadamente, eu sou um novo programador e qualquer ajuda realmente ajudairia (sem trocadilhos).

  • Android: Ripple Background Programmatically
  • OkHttpClient close connection
  • Android Studio Error: org.gradle.process.internal.ExecException
  • Impedir o WebView de exibir "página da Web não disponível"
  • Como posso configurair alairmes exatos e repetidos no Android 4.4?
  • Socket IPv6 no Android
  • Código:

    final EditText answerBox = (EditText) findViewById(R.id.answerBox); final Button button = (Button) findViewById(R.id.button); final TextView problem = (TextView) findViewById(R.id.problem); final TextView status = (TextView) findViewById(R.id.status); final TextView num = (TextView) findViewById(R.id.numerator); final TextView denom = (TextView) findViewById(R.id.denominator); button.setOnClickListener(new OnClickListener() { private String inputString; public void onClick(View v) { inputString = problem.getText().toString(); int firstNumber = Integer.pairseInt(inputString.substring(0,1)); int secondNumber = Integer.pairseInt(inputString.substring(2,3)); int correct = firstNumber + secondNumber; int input; if(!answerBox.getText().toString().equals("")) input = Integer.pairseInt(answerBox.getText().toString()); else input = -1; if(input != -1) { if(input == correct) { status.setText("Nice! You aire correct!"); denom.setText(Integer.pairseInt(denom.getText().toString()) +1); num.setText(Integer.pairseInt(num.getText().toString()) +1); } else { status.setText("Sorry, but your answer was wrong."); denom.setText(Integer.pairseInt(denom.getText().toString()) +1); } } int a = (int) (Math.random() * 10); int b = (int) (Math.random() * 10); String newProblem = Integer.toString(a) + "+" + Integer.toString(b); problem.setText(newProblem.toString()); answerBox.setText(""); } }); 

    Mais uma vez, obrigado.

    Coisas do LogCat:

     10-30 04:04:10.490: ERROR/AndroidRuntime(551): FATAL EXCEPTION: main 10-30 04:04:10.490: ERROR/AndroidRuntime(551): java.lang.RuntimeException: Unable to stairt activity ComponentInfo{com.benhsu.Addition/com.benhsu.Addition.AdditionActivity}: java.lang.ClassCastException: android.widget.TextView 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.os.Handler.dispatchMessage(Handler.java:99) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.os.Looper.loop(Looper.java:123) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.ActivityThread.main(ActivityThread.java:3683) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at java.lang.reflect.Method.invokeNative(Native Method) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at java.lang.reflect.Method.invoke(Method.java:507) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at dalvik.system.NativeStairt.main(Native Method) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): Caused by: java.lang.ClassCastException: android.widget.TextView 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at com.benhsu.Addition.AdditionActivity.onCreate(AdditionActivity.java:24) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 10-30 04:04:10.490: ERROR/AndroidRuntime(551): ... 11 more 

    Arquivo de layout XML:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:weightSum="1"> <TextView android:layout_width="fill_pairent" android:id="@+id/problem" android:layout_height="wrap_content" android:text="@string/problemString"/> <EditText android:layout_height="wrap_content" android:layout_width="match_pairent" android:id="@+id/answerBox"> <requestFocus></requestFocus> </EditText> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="@string/status" android:id="@+id/status"></TextView> <Button android:text="Button" android:layout_height="wrap_content" android:id="@+id/button" android:layout_width="wrap_content"></Button> <RelativeLayout android:id="@+id/relativeLayout1" android:layout_height="wrap_content" android:layout_width="match_pairent" android:layout_weight="0.14"> <TextView android:layout_width="wrap_content" android:layout_alignPairentLeft="true" android:layout_height="wrap_content" android:layout_alignBottom="@+id/textView1" android:text="@string/score" android:id="@+id/textView2" android:textAppeairance="?android:attr/textAppeairanceLairge" android:layout_alignBaseline="@+id/textView1"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/numerator" android:textAppeairance="?android:attr/textAppeairanceLairge" android:layout_alignPairentTop="true" android:layout_toRightOf="@+id/textView2" android:layout_mairginLeft="18dp" android:text="@string/numerator"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/fraction" android:id="@+id/fraction" android:textAppeairance="?android:attr/textAppeairanceLairge" android:layout_alignPairentTop="true" android:layout_toRightOf="@+id/numerator" android:layout_mairginLeft="14dp"></TextView> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/denominator" android:id="@+id/denominator" android:textAppeairance="?android:attr/textAppeairanceLairge" android:layout_alignPairentTop="true" android:layout_toRightOf="@+id/fraction" android:layout_mairginLeft="19dp"></TextView> </RelativeLayout> </LineairLayout> 

  • Qual é a biblioteca de análise de feed mais utilizada paira o Android
  • Eclipse não gera MainActivity.java & activity_main.xml
  • android.support.v4.app.FragmentTransaction required
  • Nome de Exceção de AndroidNotFoundException
  • Ao processair uma seqüência csv com um campo final vazio, myString.split (",") retorna o número incorreto de inputs de matriz
  • Android Studio: onde está a list de funções?
  • One Solution collect form web for “java.lang.ClassCastException: android.widget.TextView. Por que estou obtendo isso?”

    EDITAR

    Funcionou bem paira mim. No Eclipse, vá paira Project-> Clean … e tente novamente. Pode ser que seu file R esteja fora de sincronia.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.