Android 当我运行应用程序时,它会显示一条消息:您的应用程序意外停止了。怎么了?
这是我的原木猫 原木猫 这是我的密码Android 当我运行应用程序时,它会显示一条消息:您的应用程序意外停止了。怎么了?,android,Android,这是我的原木猫 原木猫 这是我的密码 你的logcat清楚地说: Caused by: java.lang.ClassCastException: android.widget.ImageButton 11-04 10:22:26.709: E/AndroidRuntime(384): at 您试图将ImageButton转换为Button,但这是错误的。因此,请执行以下操作: ImageButton call = (ImageButton) findViewById(R.id.call);
你的logcat清楚地说:
Caused by: java.lang.ClassCastException: android.widget.ImageButton 11-04 10:22:26.709: E/AndroidRuntime(384): at
您试图将ImageButton转换为Button,但这是错误的。因此,请执行以下操作:
ImageButton call = (ImageButton) findViewById(R.id.call);
并确保您的activity\u main.xml布局中有id为call的ImageButton…需要使用:
Intent makecall = new Intent(Intent.ACTION_CALL);
makecall.setData(Uri.parse("tel:0774459581"));
startActivity(makecall);
你也有
Caused by: java.lang.ClassCastException: android.widget.ImageButton 11-04 10:22:26.709: E/AndroidRuntime(384): at
所以必须确保xml文件中有ImageButton
如果xml文件中有ImageButton,则需要更改
Button call = (Button) findViewById(R.id.call);
到
将按钮更改为ImageButton
ImageButton ImageButtoncall = (ImageButton) findViewById(R.id.call);
ImageButtoncall.callsetOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent makecall = new Intent
(Intent.ACTION_DIAL,Uri.parse("tel 0774459581") );
startActivity(makecall);
}
});
在XML中,您可能有一个ImageButton,您试图将其分配给错误的按钮
java.lang.Object
↳ android.view.View
↳ android.widget.ImageView
↳ android.widget.ImageButton
使用ImageButton或其任何祖先
以这种方式替换代码
Intent makecall = new Intent(Intent.ACTION_CALL);
makecall.setData(Uri.parse("tel 0774459581")J);
startActivity(makecall);
将您的活动张贴到主页上。xml@MD提供了答案。。。
ImageButton ImageButtoncall = (ImageButton) findViewById(R.id.call);
ImageButtoncall.callsetOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent makecall = new Intent
(Intent.ACTION_DIAL,Uri.parse("tel 0774459581") );
startActivity(makecall);
}
});
java.lang.Object
↳ android.view.View
↳ android.widget.ImageView
↳ android.widget.ImageButton
Intent makecall = new Intent(Intent.ACTION_CALL);
makecall.setData(Uri.parse("tel 0774459581")J);
startActivity(makecall);