2013-04-30 2 views
0

Я получаю ошибку ClassCastException. Я не знаю почему. Пытался убрать мой проект, но ничего не случилось. Спасибо заранее!java.lang.ClassCastException: android.widget.TextView ERROR

LogCat:

04-30 18:03:44.122: W/dalvikvm(276): threadid=1: thread exiting with uncaught exception (group=0x4001d800) 
04-30 18:03:44.142: E/AndroidRuntime(276): FATAL EXCEPTION: main 
04-30 18:03:44.142: E/AndroidRuntime(276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.letsplay.gamster/com.letsplay.gamster.TutorialOne}: java.lang.ClassCastException: android.widget.TextView 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627) 
04-30 18:03:44.142: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method) 
04-30 18:03:44.142: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521) 
04-30 18:03:44.142: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 
04-30 18:03:44.142: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 
04-30 18:03:44.142: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method) 
04-30 18:03:44.142: E/AndroidRuntime(276): Caused by: java.lang.ClassCastException: android.widget.TextView 
04-30 18:03:44.142: E/AndroidRuntime(276): at com.letsplay.gamster.TutorialOne.onCreate(TutorialOne.java:28) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
04-30 18:03:44.142: E/AndroidRuntime(276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 
04-30 18:03:44.142: E/AndroidRuntime(276): ... 11 more 
04-30 18:03:44.172: W/ActivityManager(59): Force finishing activity com.letsplay.gamster/.TutorialOne 
04-30 18:03:44.182: W/ActivityManager(59): Force finishing activity com.letsplay.gamster/.menu 
04-30 18:03:44.651: I/ARMAssembler(59): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x315a58:0x315b14] in 398622 ns 
04-30 18:03:44.681: W/ActivityManager(59): Activity pause timeout for HistoryRecord{45071338 com.letsplay.gamster/.TutorialOne} 
04-30 18:03:45.791: I/Process(276): Sending signal. PID: 276 SIG: 9 
04-30 18:03:45.811: I/ActivityManager(59): Process com.letsplay.gamster (pid 276) has died. 

/////////////////////////////////// /////////////////////////////////////////////// Java:

package com.letsplay.gamster; 

import android.app.Activity; 
import android.graphics.Typeface; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.RadioGroup; 
import android.widget.RadioGroup.OnCheckedChangeListener; 
import android.widget.TextView; 

public class TutorialOne extends Activity implements OnCheckedChangeListener { 

    TextView textOut; 
    EditText textIn; 
    RadioGroup radioG, styleG; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.tutorial1); 
     textOut = (TextView) findViewById(R.id.textChanges); 
     textIn = (EditText) findViewById(R.id.editText1); 
     radioG = (RadioGroup) findViewById(R.id.textGravity); 
     radioG.setOnCheckedChangeListener(this); 

     styleG = (RadioGroup) findViewById(R.id.textStyle); 
     styleG.setOnCheckedChangeListener(this); 

     Button ok1 = (Button) findViewById(R.id.buttonOK); 
     ok1.setOnClickListener(new View.OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       textOut.setText(textIn.getText()); 

      } 
     }); 
    } 

    public void onCheckedChanged(RadioGroup group, int checkedId) { 
     // TODO Auto-generated method stub 
     switch(checkedId){ 
     case R.id.radioLeft: 
      textOut.setGravity(Gravity.LEFT); 
      break; 
     case R.id.radioCenter: 
      textOut.setGravity(Gravity.CENTER); 
      break; 
     case R.id.radioRight: 
      textOut.setGravity(Gravity.RIGHT); 
      break; 
     case R.id.radioNormal: 
      textOut.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL); 
     break; 
     case R.id.radioBold: 
      textOut.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD); 
     break; 
     case R.id.radioItalic: 
      textOut.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC); 
     break; 
     } 

    } 

} 

/////////////////////////////////////// ///////////////////////////// xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <EditText android:text="" android:id="@+id/editText1" 
     android:layout_width="fill_parent" android:layout_height="wrap_content" /> 



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" android:layout_height="wrap_content" 
     android:orientation="horizontal" android:weightSum="2"> 

     <TextView android:id="@+id/textStyle" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:layout_weight="1" 
      android:gravity="center" android:text="Style" android:textStyle="bold" /> 


     <TextView android:id="@+id/textGravity" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:layout_weight="1" 
      android:gravity="center" android:text="Gravity" android:textStyle="bold" /> 


    </LinearLayout> 

    <LinearLayout android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:orientation="horizontal" 
     android:weightSum="2"> 

     <RadioGroup android:id="@+id/radioStyle" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:layout_weight="1" android:orientation="vertical"> 


      <RadioButton android:id="@+id/radioNormal" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:text="Normal" /> 

      <RadioButton android:id="@+id/radioItalic" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:text="Italic" /> 

      <RadioButton android:id="@+id/radioBold" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:text="Bold" /> 
     </RadioGroup> 

     <RadioGroup android:id="@+id/radioGravity" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:layout_weight="1" android:orientation="vertical"> 

      <RadioButton android:id="@+id/radioLeft" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:text="Left" /> 

      <RadioButton android:id="@+id/radioCenter" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:text="Center" /> 

      <RadioButton android:id="@+id/radioRight" 
       android:layout_width="match_parent" android:layout_height="wrap_content" 
       android:text="Right" /> 
     </RadioGroup> 
    </LinearLayout> 

    <TextView android:id="@+id/textChanges" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:gravity="center_horizontal" 
     android:text="Введите текст" /> 

    <Button android:id="@+id/buttonOK" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:text="OK" /> 


</LinearLayout> 
+1

Проверьте XML для TutorialOne и убедитесь, что "андроид: ID = textChanges" является 'TextView' также пожалуйста вывесить XML – Matt

+0

Покажите нам свой XML-макет – Ahmad

+0

'textOut' не объявлен как TextView в layout.xml – etienne

ответ

0

ты понравилась classs в Androidmenifest.xml файла, подобное утверждение

<activity 
android:name="com.example1.test.Splash" 
android:label="@string/app_name" > 
<intent-filter> 
<action android:name="android.intent.action.MAIN" /> 
<category android:name="android.intent.category.LAUNCHER" /> 
</intent-filter> 
</activity> 

 Смежные вопросы

  • Нет связанных вопросов^_^