亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

將元素綁定到代碼后,為什么我的代碼總是收到空指針異常?我在Android Studio中使用Java

將元素綁定到代碼后,為什么我的代碼總是收到空指針異常?我在Android Studio中使用Java

牛魔王的故事 2021-04-09 14:14:09
盡管我已經正確綁定了元素,但是我正在接收java.lang.NullPointerException。試圖檢查元素的ID,它匹配,但是我仍然收到相同的異常。MainActivity.java@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    //Text to Speech    tts = new TextToSpeech(this, this);    speakButton = findViewById(R.id.speakButton);    speechText = findViewById(R.id.speechText);    speakButton.setOnClickListener(new View.OnClickListener() {        @Override        public void onClick(View v) {            speakOut();        }    });    // End    loadFragment(new HomeFragment());    BottomNavigationView navigation = findViewById(R.id.navigation);    navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);}TranslatorFragment.javapublic class TranslatorFragment extends Fragment {public Button speakButton;public TranslatorFragment(){    //Empty Constructor}@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {    return inflater.inflate(R.layout.translator_fragment, container, false);}public void onActivityCreated(Bundle savedInstanceState) {    super.onActivityCreated(savedInstanceState);}@Overridepublic void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {    super.onViewCreated(view, savedInstanceState);    speakButton = view.findViewById(R.id.speakButton);}}它應該運行正常,但是我收到了java.lang.NullPointerException
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 215 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

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

公眾號

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