我是一名机器人初学者(我的第一篇文章)并且在运行这个bmi计算器教程时遇到了崩溃:http://android-meda.blogspot.co.uk/2012/01/writing-your-first-android-app-body.html?m=1
在我的手机上发布,屏幕变黑,显示“BMI已经停止”。我不确定在哪里诊断问题,所以任何帮助将不胜感激。 谢谢
04-04 14:14:44.750: E/SensorManager(24999): thread start
04-04 14:14:44.755: D/SensorManager(24999): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@42b75490
04-04 14:14:44.760: D/SensorManager(24999): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@42b75490
04-04 14:14:44.760: D/Sensors(24999): Remain listener = Sending .. normal delay 200ms
04-04 14:14:44.760: I/Sensors(24999): sendDelay --- 200000000
04-04 14:14:44.765: D/SensorManager(24999): JNI - sendDelay
04-04 14:14:44.765: I/SensorManager(24999): Set normal delay = true
04-04 14:14:44.815: D/SensorManager(24999): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@42b75490
04-04 14:14:44.870: D/libEGL(24999): loaded /system/lib/egl/libEGL_mali.so
04-04 14:14:44.875: D/libEGL(24999): loaded /system/lib/egl/libGLESv1_CM_mali.so
04-04 14:14:44.880: D/libEGL(24999): loaded /system/lib/egl/libGLESv2_mali.so
04-04 14:14:44.885: D/(24999): Device driver API match
04-04 14:14:44.885: D/(24999): Device driver API version: 10
04-04 14:14:44.885: D/(24999): User space API version: 10
04-04 14:14:44.885: D/(24999): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
04-04 14:14:44.910: D/OpenGLRenderer(24999): Enabling debug mode 0
04-04 14:14:44.985: W/IInputConnectionWrapper(24999): showStatusIcon on inactive InputConnection
04-04 14:14:52.235: D/SensorManager(24999): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@42b75490
04-04 14:14:52.235: D/Sensors(24999): Remain listener = Sending .. normal delay 200ms
04-04 14:14:52.235: I/Sensors(24999): sendDelay --- 200000000
04-04 14:14:52.235: D/SensorManager(24999): JNI - sendDelay
04-04 14:14:52.235: I/SensorManager(24999): Set normal delay = true
04-04 14:14:52.240: D/SensorManager(24999): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@42b78da8
04-04 14:14:52.260: W/IInputConnectionWrapper(24999): getSelectedText on inactive InputConnection
04-04 14:14:52.265: W/IInputConnectionWrapper(24999): setComposingText on inactive InputConnection
04-04 14:14:52.265: W/IInputConnectionWrapper(24999): getExtractedText on inactive InputConnection
04-04 14:14:53.420: D/AndroidRuntime(24999): Shutting down VM
04-04 14:14:53.420: W/dalvikvm(24999): threadid=1: thread exiting with uncaught exception (group=0x41f052a0)
04-04 14:14:53.430: E/AndroidRuntime(24999): FATAL EXCEPTION: main
04-04 14:14:53.430: E/AndroidRuntime(24999): java.lang.IllegalStateException: Could not execute method of the activity
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View$1.onClick(View.java:3691)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View.performClick(View.java:4211)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View$PerformClick.run(View.java:17267)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.os.Handler.handleCallback(Handler.java:615)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.os.Handler.dispatchMessage(Handler.java:92)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.os.Looper.loop(Looper.java:137)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.app.ActivityThread.main(ActivityThread.java:4898)
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 14:14:53.430: E/AndroidRuntime(24999): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
04-04 14:14:53.430: E/AndroidRuntime(24999): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
04-04 14:14:53.430: E/AndroidRuntime(24999): at dalvik.system.NativeStart.main(Native Method)
04-04 14:14:53.430: E/AndroidRuntime(24999): Caused by: java.lang.reflect.InvocationTargetException
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invokeNative(Native Method)
04-04 14:14:53.430: E/AndroidRuntime(24999): at java.lang.reflect.Method.invoke(Method.java:511)
04-04 14:14:53.430: E/AndroidRuntime(24999): at android.view.View$1.onClick(View.java:3686)
04-04 14:14:53.430: E/AndroidRuntime(24999): ... 11 more
04-04 14:14:53.430: E/AndroidRuntime(24999): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
04-04 14:14:53.430: E/AndroidRuntime(24999): at com.example.bmi.MainActivity.calculateClickHandler(MainActivity.java:22)
04-04 14:14:53.430: E/AndroidRuntime(24999): ... 14 more
答案 0 :(得分:0)
您正在尝试将TextView转换为EditText:
Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
检查你的代码(TextView)变量=(EditText)findViewById(..)......
问题出在MainActivity.java文件的第22行。
如果您分析粘贴的堆栈跟踪:
Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
at com.example.bmi.MainActivity.calculateClickHandler(MainActivity.java:22)
它指出了问题所在(MainActivity.java:22)。这意味着您的MainActivity.java文件中的第22行。
更好的是,如果找不到问题,请在此处粘贴代码段,以便我可以更具体地指出问题所在。您应该从onClick侦听器发布代码
EditText用于编辑文本,TextView是用于显示文本的组件。因此它们不兼容。第一个是可编辑的表单元素,而后者仅用于显示目的。你不能把一个投入另一个。