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

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是否初始化啦

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 VMware安装虚拟网络驱动程序不成功,如何解决?(操作系统-linux)
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件