E/AndroidRuntime(30895): Caused by: java.lang.ClassCastException: android.widget.ImageButton
来源:互联网 发布:广联达软件管家打不开 编辑:程序博客网 时间:2024/05/22 09:03
本程序是实现点击图片按钮跳转到下一页,出现的问题在于点击后软件出错。
Activity代码
package com.example.test;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ImageButton;import android.app.Activity;import android.content.Intent;public class SecondActivity extends Activity {private Button button1;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_second);button1 = (Button)findViewById(R.id.image);button1.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {// TODO 自动生成的方法存根Intent intent=new Intent();intent.setClass(SecondActivity.this,userlist.class);startActivity(intent);}});}}
下列代码为ImageButton代码
<ImageButton android:src="@drawable/shui" android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:padding="10dip" android:paddingLeft="40dip" android:paddingRight="40dip" android:paddingTop="40dp" android:layout_weight="1" android:background="#00000000" />
出错的原因在于布局文件使用的是ImageButton按钮,而在Activity中未声明和使用ImageButton。
注意:在布局文件使用到ImageButton控件的时候,需要在Activity中也使用ImageButton与之对应。
调试方法:将private Button button1;改为private ImageButton button1; 将button1 = (Button)findViewById(R.id.image);改为button1 = (ImageButton)findViewById(R.id.image);
0 0
- E/AndroidRuntime(30895): Caused by: java.lang.ClassCastException: android.widget.ImageButton
- ERROR/AndroidRuntime: Caused by: java.lang.ClassCastException: android.widget.button
- 错误:E/AndroidRuntime(6539): Caused by: java.lang.ClassCastException: android.widget.
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout
- 转 Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.TextView修复
- Caused by: java.lang.ClassCastException: android.widget.TextView修复
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
- Caused by: java.lang.ClassCastException: android.widget.TextView修复
- Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 错误
- Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Bu
- Android异常总结---E/AndroidRuntime(23439): Caused by: java.lang.IllegalArgumentException: column '_id' d
- Android错误总结-E/AndroidRuntime(23439): Caused by: java.lang.IllegalArgumentException: column 'id' d
- Android异常总结---E/AndroidRuntime(23439): Caused by: java.lang.IllegalArgumentException: column '_id' d
- 【Android笔记-异常-2】Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatButton c
- 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT)
- hihocoder第三周KMP算法(睡了一觉突然一个灵感出现就把这道题解出来了)
- windows命令行工具
- 18.1.2 目录实用工具
- 填报下发
- E/AndroidRuntime(30895): Caused by: java.lang.ClassCastException: android.widget.ImageButton
- 使用 ICMP 和 RAW Sockets实现 ping 类
- [SPFA的SLF优化] Codeforces Round #257 (Div. 1) B
- 千万不要买小胖子u盘
- Intent 用法全面总结
- [Java-码农]win7(windows7)下java环境变量配置方法
- 多线程GCD的使用
- mfc的dll添加
- POJ 2635 The Embarrassed Cryptographer