第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何修復 'com.example.app15.MainActivity.onCreate' 錯誤

如何修復 'com.example.app15.MainActivity.onCreate' 錯誤

慕神8447489 2023-05-24 16:19:11
單擊圖像時,我試圖創(chuàng)建一個活動鏈接。我無法運行該應用程序。它顯示“應用程序不斷關閉”。網上查了一下,認為是空指針異常。即使是我也找不到解決方案。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)
查看完整描述

2 回答

?
白板的微信

TA貢獻1883條經驗 獲得超3個贊

改為private Button button1_private ImageButton button1



查看完整回答
反對 回復 2023-05-24
?
嗶嗶one

TA貢獻1854條經驗 獲得超8個贊

您導入了錯誤的類。如果要使用Button,則導入Button,如果要使用ImageButton,則導入ImageButton。嘗試檢查導入的類是否正確



查看完整回答
反對 回復 2023-05-24
  • 2 回答
  • 0 關注
  • 155 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號