Fragment中的代码 context 是null
public class PlaceholderFragment extends Fragment{ Context context = getActivity(); }
Activity中的代码 context不是null
public class MainActivity extends FragmentActivity { Context context = this; }
下面这种方式获取context 会抛异常
public class MainActivity extends FragmentActivity { Context context = getApplicationContext();; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/pcaxb/article/details/46911067