0

嘿伙计们,我对制作应用程序真的很陌生,这是我启动应用程序时发生的错误。如果你们中的一个人能告诉我如何逐步解决这个问题,我将非常感激:) 谢谢,记录:

   08-04 17:02:45.480: D/AndroidRuntime(464): Shutting down VM
   08-04 17:02:45.480: W/dalvikvm(464): threadid=1: thread exiting with uncaught exception (group=0x40015560)
   08-04 17:02:45.499: E/AndroidRuntime(464): FATAL EXCEPTION: main
   08-04 17:02:45.499: E/AndroidRuntime(464): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dice.alt/com.dice.alt.DiceAlternativeActivity}: java.lang.ClassCastException: android.widget.TextView
   08-04 17:02:45.499: E/AndroidRuntime(464):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
   08-04 17:02:45.499: E/AndroidRuntime(464):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
   08-04 17:02:45.499: E/AndroidRuntime(464):   at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at android.os.Handler.dispatchMessage(Handler.java:99)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at android.os.Looper.loop(Looper.java:123)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at android.app.ActivityThread.main(ActivityThread.java:3683)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at java.lang.reflect.Method.invokeNative(Native Method)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at java.lang.reflect.Method.invoke(Method.java:507)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at dalvik.system.NativeStart.main(Native Method)
  08-04 17:02:45.499: E/AndroidRuntime(464): Caused by: java.lang.ClassCastException: android.widget.TextView
  08-04 17:02:45.499: E/AndroidRuntime(464):    at com.dice.alt.DiceAlternativeActivity.onCreate(DiceAlternativeActivity.java:20)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  08-04 17:02:45.499: E/AndroidRuntime(464):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
  08-04 17:02:45.499: E/AndroidRuntime(464):    ... 11 more
  08-04 17:02:48.179: I/Process(464): Sending signal. PID: 464 SIG: 9</i>'

XML:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/android:list"
    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="409dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/ndice"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#4876FF" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:text="@string/empty" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/udice"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#4876FF" />

        <EditText
            android:id="@+id/editText2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="number"
            android:text="@string/empty" />

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/result" />

        <TextView
            android:id="@+id/op"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#DC143C"
            android:layout_weight="0.54"
            android:text="@string/empty"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/ABJ2"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#32CD32" />

    </LinearLayout>
</ScrollView>
4

1 回答 1

1

Caused by: java.lang.ClassCastException: android.widget.TextView

-日志中的上述行表明在尝试将一种类型的变量转换为不兼容的类型时出现异常。

-您要么尝试将不兼容的内容转换为 TextView 类型变量,要么将 TextView 转换为不兼容的类型。

例如:

Button b = (TextView)findViewById(R.id.mbut);

于 2012-08-04T12:43:56.633 回答