繁体   English   中英

Android中具有3个活动的多项活动

[英]Multiple Activities in Android with 3 Activites

我正在Android中创建多个activities ,这是我的logcat错误输出。

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

多谢你们 :)

如果我算对的话

ibHome3 = (Button) findViewById(R.id.ibHome3);

造成您的问题。 您在xml中将其作为ImageButton ,而在Java声明中将其作为Button 只需将其更改为

ImageButton ibHome3;

关于Logcat

另外,关于logcat的一些建议。 如果你发现说,第一行Caused ByFatal Exception ,你可以更容易跟踪你的问题。 这里是

 Caused by: java.lang.ClassCastException: android.widget.ImageButton cannot be cast to android.widget.Button

这给出了例外

java.lang.ClassCastException

然后找到引用您的软件包的第一行。 这里

at com.jumoun.itemp.Converter.onCreate(Converter.java:41)

这告诉我们问题开始于Converter.java的41行

您的布局文件中有两个按钮,对吗? 它们看起来被定义为XML文件中的ImageButton。 在您的活动中,将其声明为Button,然后尝试将其转换为(Button)。 将您的类型更改为活动文件上的ImageButton。 它可能会解决您的问题。

在第41行,您必须将按钮投射到ImageButton而不是Button:

ibHome3 = (ImageButton) findViewById(R.id.ibHome3);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM