android_new_bird
2016-09-30 08:50
采纳率: 100%
浏览 1.0k
已采纳

android listview 内viewpager报错

private View getTopView(View convertView)
{
element = LayoutInflater.from(mContext).inflate(R.layout.vp_content, null);
//top_img=(ImageView)element.findViewById(R.id.top_img);
//top_img.setImageResource(R.drawable.ic_default);
mNewsImages.add(element);
mTopView = LayoutInflater.from(mContext).inflate(R.layout.viewpage, null);
dots.add(mTopView.findViewById(R.id.dot_1));
dots.add(mTopView.findViewById(R.id.dot_2));
dots.add(mTopView.findViewById(R.id.dot_3));
mNewsViewPager = (ViewPager)mTopView.findViewById(R.id.adViewPager);
mPageAdaper=new mPagerAdapter();
mNewsViewPager.setAdapter(mPageAdaper);
mNewsViewPager.setCurrentItem(0);
OnPageChangeListener pageChangeListener =new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
dots.get(oldPosition).setBackgroundResource(
R.drawable.dot_normal);
dots.get(position)
.setBackgroundResource(R.drawable.dot_focused);
oldPosition = position;
}
@Override
public void onPageScrollStateChanged(int state) {
}
@Override
public void onPageScrolled(int position,
float positionOffset, int positionOffsetPixels) {
}
};
mNewsViewPager.setOnPageChangeListener(pageChangeListener);

            return mTopView;

}


报错如下:
09-30 16:49:09.454: E/AndroidRuntime(26347): FATAL EXCEPTION: main

09-30 16:49:09.454: E/AndroidRuntime(26347): Process: com.codetech.codetech, PID: 26347
09-30 16:49:09.454: E/AndroidRuntime(26347): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.AbsListView.obtainView(AbsListView.java:2605)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.ListView.makeAndAddView(ListView.java:1953)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.ListView.fillDown(ListView.java:754)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.ListView.fillFromTop(ListView.java:819)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.ListView.layoutChildren(ListView.java:1748)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.AbsListView.onLayout(AbsListView.java:2332)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.View.layout(View.java:16112)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewGroup.layout(ViewGroup.java:5185)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:714)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.View.layout(View.java:16112)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewGroup.layout(ViewGroup.java:5185)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:639)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.FrameLayout.onLayout(FrameLayout.java:574)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.View.layout(View.java:16112)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewGroup.layout(ViewGroup.java:5185)
09-30 16:49:09.454: E/AndroidRuntime(26347): at com.android.internal.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:494)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.View.layout(View.java:16112)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewGroup.layout(ViewGroup.java:5185)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:639)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.widget.FrameLayout.onLayout(FrameLayout.java:574)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.View.layout(View.java:16112)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewGroup.layout(ViewGroup.java:5185)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2526)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2218)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1315)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6728)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.Choreographer.doCallbacks(Choreographer.java:603)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.Choreographer.doFrame(Choreographer.java:572)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.os.Handler.handleCallback(Handler.java:815)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.os.Handler.dispatchMessage(Handler.java:104)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.os.Looper.loop(Looper.java:194)
09-30 16:49:09.454: E/AndroidRuntime(26347): at android.app.ActivityThread.main(ActivityThread.java:5826)
09-30 16:49:09.454: E/AndroidRuntime(26347): at java.lang.reflect.Method.invoke(Native Method)
09-30 16:49:09.454: E/AndroidRuntime(26347): at java.lang.reflect.Method.invoke(Method.java:372)
09-30 16:49:09.454: E/AndroidRuntime(26347): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1009)
09-30 16:49:09.454: E/AndroidRuntime(26347): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:804)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • RoidCoder 2016-09-30 10:59
    已采纳

    NullPointerException 明显的空指针异常,看下View是否初始化啦

    点赞 评论
  • xdd123_321 2016-09-30 09:05

    是不是没有设置当前所显示的ViewPager

    点赞 评论

相关推荐 更多相似问题