Android应用程序在打开时立即崩溃

时间:2012-02-21 16:42:38

标签: java android eclipse

我正在开发一个Android应用程序,在我点击运行后,我解锁AVD并单击菜单加载我的应用程序,我立即得到“应用程序意外关闭”消息。

以下是我的logcat的输出:

02-21 11:36:55.952: D/AndroidRuntime(329): Shutting down VM
02-21 11:36:55.952: W/dalvikvm(329): threadid=1: thread exiting with uncaughtexception (group=0x40015560)
02-21 11:36:55.971: E/AndroidRuntime(329): FATAL EXCEPTION: main
02-21 11:36:55.971: E/AndroidRuntime(329): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.throughputconverter/com.throughputconverter.ThroughputConverterActivity}: java.lang.ClassCastException: android.widget.EditText
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.os.Looper.loop(Looper.java:123)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.ActivityThread.main(ActivityThread.java:3683)
02-21 11:36:55.971: E/AndroidRuntime(329):  at java.lang.reflect.Method.invokeNative(Native Method)
02-21 11:36:55.971: E/AndroidRuntime(329):  at java.lang.reflect.Method.invoke(Method.java:507)
02-21 11:36:55.971: E/AndroidRuntime(329):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-21 11:36:55.971: E/AndroidRuntime(329):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-21 11:36:55.971: E/AndroidRuntime(329):  at dalvik.system.NativeStart.main(Native Method)
02-21 11:36:55.971: E/AndroidRuntime(329): Caused by: java.lang.ClassCastException: android.widget.EditText
02-21 11:36:55.971: E/AndroidRuntime(329):  at com.throughputconverter.ThroughputConverterActivity.onCreate(ThroughputConverterActivity.java:44)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-21 11:36:55.971: E/AndroidRuntime(329):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-21 11:36:55.971: E/AndroidRuntime(329):  ... 11 more 

3 个答案:

答案 0 :(得分:2)

您似乎正在向EditText投射对象,但此对象不属于此类:

java.lang.ClassCastException: android.widget.EditText

你能提供第44行吗?

答案 1 :(得分:2)

看起来您正在错误地投射EditText小部件,或者您的布局和/或活动中不存在小部件。

答案 2 :(得分:0)

我遇到了同样的错误

为原因搜索了一切 在我的情况下没有任何工作 然后仔细查看资源xml

我最近更改了添加的元素

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:id="@+id/bClick2"
android:background="@drawable/new1"
android:layout_gravity="bottom">
</Button>

<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" 
android:id="@+id/bClick2"
android:background="@drawable/new1"
android:layout_gravity="bottom"/>

我的问题解决了。