posts - 93,  comments - 2,  trackbacks - 0
Exception:
    10-24 17:43:15.112: E/AndroidRuntime(11888): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.ViewGroup.addViewInner(ViewGroup.java:3596)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.ViewGroup.addView(ViewGroup.java:3449)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.support.v4.view.ViewPager.addView(ViewPager.java:1305)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.ViewGroup.addView(ViewGroup.java:3394)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.ViewGroup.addView(ViewGroup.java:3370)
10-24 17:43:15.112: E/AndroidRuntime(11888): at com.zhihe.xqsh.adapter.IndexTopPagerAdapter.instantiateItem(IndexTopPagerAdapter.java:72)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:833)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.support.v4.view.ViewPager.populate(ViewPager.java:1017)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.support.v4.view.ViewPager.populate(ViewPager.java:915)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.support.v4.view.ViewPager$3.run(ViewPager.java:245)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.Choreographer.doFrame(Choreographer.java:543)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.os.Handler.handleCallback(Handler.java:733)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.os.Handler.dispatchMessage(Handler.java:95)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.os.Looper.loop(Looper.java:136)
10-24 17:43:15.112: E/AndroidRuntime(11888): at android.app.ActivityThread.main(ActivityThread.java:5050)
10-24 17:43:15.112: E/AndroidRuntime(11888): at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:43:15.112: E/AndroidRuntime(11888): at java.lang.reflect.Method.invoke(Method.java:515)
10-24 17:43:15.112: E/AndroidRuntime(11888): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)
10-24 17:43:15.112: E/AndroidRuntime(11888): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)
10-24 17:43:15.112: E/AndroidRuntime(11888): at dalvik.system.NativeStart.main(Native Method)
10-24 17:43:15.132: I/Process(11888): Sending signal. PID: 11888 SIG: 9

原因:
    当图片向左滑动的时候,之后执行instantiateItem方法,而不去执行删除方法,所以出现上述异常
    所以在instantiateItem方法中执行删除操作,如下:
    View child = mPageViewList.get(position);
if(child.getParent()!=null){
((ViewPager)container).removeView(child);
}
    注意,在此执行了删除操作之后,把destroyItem方法中的删除去掉,因为,如果不去掉向左滑动的时候,会显示为空,原因如下:打印url是进行加载View,当加载完成之后会去执行destroyItem中的方法,所以,需要把destroyItem中的删除去掉。
10-24 17:49:14.452: W/(16419): ----zhihe---- IndextoppagerAdapter instantiateItem position:0
10-24 17:49:14.452: W/(16419): ----zhihe---- IndextoppagerAdapter instantiateItem image:http://ys.rili.com.cn/images/image/201401/0111174780.jpg
10-24 17:49:14.462: W/(16419): ----zhihe---- IndextoppagerAdapter destroyItem position:0
posted on 2014-10-24 17:53 Terry Zou 阅读(1318) 评论(0)  编辑  收藏 所属分类: Android

只有注册用户登录后才能发表评论。


网站导航:
 
<2014年10月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

Java

搜索

  •  

最新随笔

最新评论

阅读排行榜

评论排行榜