在Android的多种活动与3 Activites [英] Multiple Activities in Android with 3 Activites
问题描述
我创建多个活动
在Android中,这是我的logcat错误输出。
I am creating multiple activities
in Android, this is my logcat error output.
log.txt中
05-03 03:17:23.295: E/PhonePolicy(1854): Could not preload class for phone policy: com.android.internal.policy.impl.PhoneWindow$ContextMenuCallback
05-03 03:17:37.044: W/dalvikvm(1854): threadid=1: thread exiting with uncaught exception (group=0x409db1f8)
05-03 03:17:37.044: E/AndroidRuntime(1854): FATAL EXCEPTION: main
05-03 03:17:37.044: E/AndroidRuntime(1854): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jumoun.itemp/com.jumoun.itemp.Converter}: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.os.Handler.dispatchMessage(Handler.java:99)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.os.Looper.loop(Looper.java:137)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.ActivityThread.main(ActivityThread.java:4427)
05-03 03:17:37.044: E/AndroidRuntime(1854): at java.lang.reflect.Method.invokeNative(Native Method)
05-03 03:17:37.044: E/AndroidRuntime(1854): at java.lang.reflect.Method.invoke(Method.java:511)
05-03 03:17:37.044: E/AndroidRuntime(1854): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
05-03 03:17:37.044: E/AndroidRuntime(1854): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
05-03 03:17:37.044: E/AndroidRuntime(1854): at dalvik.system.NativeStart.main(Native Method)
05-03 03:17:37.044: E/AndroidRuntime(1854): Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
05-03 03:17:37.044: E/AndroidRuntime(1854): at com.jumoun.itemp.Converter.onCreate(Converter.java:41)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.Activity.performCreate(Activity.java:4465)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-03 03:17:37.044: E/AndroidRuntime(1854): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-03 03:17:37.044: E/AndroidRuntime(1854): ... 11 more
05-03 03:17:38.704: I/Process(1854): Sending signal. PID: 1854 SIG: 9
这是我的Java文件 Converter.java
http://pastebin.com/VNNPy7D5
This is my java file Converter.java
http://pastebin.com/VNNPy7D5
感谢球员:)
推荐答案
如果我算这个权
ibHome3 = (Button) findViewById(R.id.ibHome3);
是造成你的问题。你必须把它作为你的Java声明的的ImageButton
在你的XML,但按钮
。只需将其更改为
is causing your problem. You have it as an ImageButton
in your xml but Button
in your java declaration. Just change it to
ImageButton ibHome3;
关于logcat的
此外,在logcat的只是一个小建议。如果您发现的第一行写着所引发
在致命异常
您可以跟踪您的问题更容易。这是
Also, just a little advice on logcat. If you find the first line that says Caused By
after Fatal Exception
you can track down your problem easier. Here it is
Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button
这给出了异常
java.lang.ClassCastException
然后找到后它引用你的包的第一行。在这里,
then find the first line after that which references your package. Here
at com.jumoun.itemp.Converter.onCreate(Converter.java:41)
这告诉我们,这个问题在41线开始于 Converter.java
this tells us the problem starts in Converter.java
at line 41
这篇关于在Android的多种活动与3 Activites的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!