0

好的,在他的示例中,他指出 PullToRefreshAttacher 应该始终在 onCreate 中创建。

但是,使用我的代码

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,那么这里的错误是什么?

这是我的日志:

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
4

1 回答 1

2

尝试改变

 mPullToRefreshAttacher = PullToRefreshAttacher.get(MainActivity.this);
于 2013-09-03T04:51:01.190 回答