Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference

后端 未结 2 1617
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 03:07

When my SplashActivity opens the LoginActivity my app crashes.

The following is my SplashActivity.java:

packag         


        
2条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 03:19

    Views defined in xml file can only be accessed in java code, after setting the ContentView as the required xml file using:

    setContentView(R.layout.xml_file_name);
    

    So 1st call above method inside onCreate method and then initialize the View instances inside onCreate or inside the methods in which the instance will be used.

提交回复
热议问题