打开模拟器显示 stopped logcat的错误信息无法理解

[复制链接]
查看11 | 回复1 | 2021-1-27 05:47:21 | 显示全部楼层 |阅读模式
用接口实现在两个文本框输入数字
点击按钮实现加减乘除
求大神指点
09-1513:29:14.716:E/AndroidRuntime(1120):FATALEXCEPTION:main
09-1513:29:14.716:E/AndroidRuntime(1120):Process:com.example.www,PID:1120
09-1513:29:14.716:E/AndroidRuntime(1120):java.lang.RuntimeException:UnabletostartactivityComponentInfo{com.example.www/com.example.www.MainActivity}:java.lang.ClassCastException:com.example.www.MainActivitycannotbecasttoandroid.view.View$OnClickListener
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.ActivityThread.access$800(ActivityThread.java:144)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.os.Handler.dispatchMessage(Handler.java:102)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.os.Looper.loop(Looper.java:135)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.ActivityThread.main(ActivityThread.java:5221)
09-1513:29:14.716:E/AndroidRuntime(1120):atjava.lang.reflect.Method.invoke(NativeMethod)
09-1513:29:14.716:E/AndroidRuntime(1120):atjava.lang.reflect.Method.invoke(Method.java:372)
09-1513:29:14.716:E/AndroidRuntime(1120):atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
09-1513:29:14.716:E/AndroidRuntime(1120):atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
09-1513:29:14.716:E/AndroidRuntime(1120):Causedby:java.lang.ClassCastException:com.example.www.MainActivitycannotbecasttoandroid.view.View$OnClickListener
09-1513:29:14.716:E/AndroidRuntime(1120):atcom.example.www.MainActivity.onCreate(MainActivity.java:30)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.Activity.performCreate(Activity.java:5933)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
09-1513:29:14.716:E/AndroidRuntime(1120):atandroid.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
09-1513:29:14.716:E/AndroidRuntime(1120):...10more
09-1513:29:14.746:W/ActivityManager(348):Forcefinishingactivitycom.example.www/.MainActivity
packagecom.example.www;
importandroid.support.v7.app.ActionBarActivity;

importandroid.os.Bundle;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.CompoundButton;
importandroid.widget.EditText;
importandroid.widget.RadioButton;
importandroid.widget.RadioGroup;
importandroid.widget.RadioGroup.OnCheckedChangeListener;
importandroid.widget.TextView;
publicclassMainActivityextendsActionBarActivityimplementsOnCheckedChangeListener,android.widget.CompoundButton.OnCheckedChangeListener{
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextViewtv3=(TextView)findViewById(R.id.tv3);
EditTexted1=(EditText)findViewById(R.id.edi1);
EditTexted2=(EditText)findViewById(R.id.edi2);
Buttonb1=(Button)findViewById(R.id.button1);
RadioButtonr1=(RadioButton)findViewById(R.id.radio1);
RadioButtonr2=(RadioButton)findViewById(R.id.radio2);
RadioButtonr3=(RadioButton)findViewById(R.id.radio3);
RadioButtonr4=(RadioButton)findViewById(R.id.radio4);
tv3.setOnClickListener((OnClickListener)this);
ed1.setOnClickListener((OnClickListener)this);
ed2.setOnClickListener((OnClickListener)this);
b1.setOnClickListener((OnClickListener)this);
r1.setOnClickListener((OnClickListener)this);
r2.setOnClickListener((OnClickListener)this);
r3.setOnClickListener((OnClickListener)this);
r4.setOnClickListener((OnClickListener)this);

}
@Override
publicvoidonCheckedChanged(CompoundButtonbuttonView,booleanisChecked){

}
@Override
publicvoidonCheckedChanged(RadioGroupgroup,intcheckedId){
EditTexted1=(EditText)findViewById(R.id.edi1);
EditTexted2=(EditText)findViewById(R.id.edi2);
inte1=Integer.parseInt(ed1.getText().toString());
inte2=Integer.parseInt(ed2.getText().toString());
TextViewtv3=(TextView)findViewById(R.id.tv3);
if(checkedId==R.id.radio1){
tv3.setText(e1+e2);
}elseif(checkedId==R.id.radio2){
tv3.setText(e1-e2);
}elseif(checkedId==R.id.radio3){
tv3.setText(e1*e2);
}elseif(checkedId==R.id.radio4){
tv3.setText(e1/e2);
}
}


}









[B]


分 -->
回复

使用道具 举报

千问 | 2021-1-27 05:47:21 | 显示全部楼层
求大神指点!!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行