[英]Android : NullPointerException when switching to other apps
This example work well. 这个例子很好用。 But when i switch to other applications, then i come back, myMethod throw a null pointer exception. 但是当我切换到其他应用程序时,我又回来了,myMethod抛出一个空指针异常。 How can i get the reference to the FragmentPagerAdapter? 我如何获得对FragmentPagerAdapter的引用?
public class MainActivity extends SherlockFragmentActivity {
private FragmentPagerAdapter tabAdapter;
private final BroadcastReceiver onNotice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
myMethod();
}
};
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
tabAdapter = new FragmentPagerAdapter();
}
protected void myMethod() {
tabAdapter.getCount(); // <-- NullPointerException
}
}
Thanks in advance 提前致谢
I guess you need to call 我想你需要打电话
tabAdapter = new FragmentPagerAdapter();
in 在
onResume()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.