嘿伙计我真的很擅长制作应用程序,这是我启动应用程序时发生的错误。如果有人能告诉我如何一步一步解决这个问题,我真的很感激:)谢谢你,记录:
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>
答案 0 :(得分:1)
Caused by: java.lang.ClassCastException: android.widget.TextView
- 您的日志中的上述行表示在尝试将一种类型的变量转换为不兼容类型时存在异常。
- 您要么尝试投射与TextView类型变量不兼容的内容,要么将TextView转换为不兼容的类型。
<强>例如强>
Button b = (TextView)findViewById(R.id.mbut);