TabLayout上的空指针异常

时间:2016-07-12 01:37:51

标签: android android-support-library

NSUserDefaults.standUserDefaults().setObject(noteTitles, forKey: "note")
NSUserDefaults.standardUserDefaults().synchronize()

在onCreate()之前声明了这个:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.design.widget.TabLayout.addOnTabSelectedListener(android.support.design.widget.TabLayout$OnTabSelectedListener)' on a null object reference

和onCreate():

TabLayout.OnTabSelectedListener listener;

我很难看到侦听器是如何为空的。我有其他NullPointerExceptions甚至声称原始对象上的null对象,包括由drawable pngs定义的int?

1 个答案:

答案 0 :(得分:1)

您忘记将布局设置为setContentView()