好的,在他的例子中,他说应该始终在onCreate中创建PullToRefreshAttacher。
然而,我的代码
public class MainActivity extends FragmentActivity {
PagerAdapter adapter;
ArrayList<ImagePanel> mListOfImagePanel = new ArrayList<ImagePanel>();
ArrayList<String> mListOfImagePanelNames = new ArrayList<String>();
ListView mDrawerList;
ArrayAdapter<String> mDrawerListAdapter;
boolean doOnce = false;
DrawerLayout mDrawerLayout;
Flipper mFlip;
PullToRefreshLayout mPullToRefreshLayout;
private PullToRefreshAttacher mPullToRefreshAttacher;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//DO THESE FIRST
setContentView(R.layout.activity_main);
mPullToRefreshAttacher = PullToRefreshAttacher.get(this); // This line, nullpointerexception
但是,当我尝试附加PullToRefreshAttacher时,它会给我一个NullPointerException,那么这里的错误是什么?
这是我的logcat:
09-03 13:04:35.437: E/AndroidRuntime(4435): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jo.universalcomicreader/com.jo.universalcomicreader.MainActivity}: java.lang.NullPointerException
09-03 13:04:35.437: E/AndroidRuntime(4435): at com.jo.universalcomicreader.DefaultHeaderTransformer.applyProgressBarColor(DefaultHeaderTransformer.java:229)
09-03 13:04:35.437: E/AndroidRuntime(4435): at com.jo.universalcomicreader.DefaultHeaderTransformer.onViewCreated(DefaultHeaderTransformer.java:67)
09-03 13:04:35.437: E/AndroidRuntime(4435): at com.jo.universalcomicreader.PullToRefreshAttacher.<init>(PullToRefreshAttacher.java:178)
09-03 13:04:35.437: E/AndroidRuntime(4435): at com.jo.universalcomicreader.PullToRefreshAttacher.get(PullToRefreshAttacher.java:105)
09-03 13:04:35.437: E/AndroidRuntime(4435): at com.jo.universalcomicreader.PullToRefreshAttacher.get(PullToRefreshAttacher.java:90)
09-03 13:04:35.437: E/AndroidRuntime(4435): at com.jo.universalcomicreader.MainActivity.onCreate(MainActivity.java:54)
09-03 13:04:35.448: E/EmbeddedLogger(619): App crashed! Process: com.jo.universalcomicreader
09-03 13:04:35.448: E/EmbeddedLogger(619): App crashed! Package: com.jo.universalcomicreader v1 (1.0)
09-03 13:04:35.448: E/EmbeddedLogger(619): Application Label: Universal Comic Reader
答案 0 :(得分:2)
尝试改变
mPullToRefreshAttacher = PullToRefreshAttacher.get(MainActivity.this);