尽管我已经正确绑定了元素,但是我正在接收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
添加回答
举报
0/150
提交
取消