单击图像时,我试图创建一个活动链接。我无法运行该应用程序。它显示“应用程序不断关闭”。网上查了一下,认为是空指针异常。即使是我也找不到解决方案。public class MainActivity extends AppCompatActivity { private Button button1; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity1); button1=findViewById(R.id.letsgo); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { openActivity1(); } }); } public void openActivity1(){ Intent intent=new Intent(this,MainActivity2.class); startActivity(intent); }}日志at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatImageButton cannot be cast to android.widget.Button at com.example.app3.MainActivity.onCreate(MainActivity.java:21) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791)
添加回答
举报
0/150
提交
取消