在初始化viewPagerAdapter时,显示异常。从网上找了找有两类这样的问题,一种是说给一个视图设置了两个父类,如:

TextView tv = new TextView();
layout.adView(tv);
layout2.adView(tv);这样就会报异常,需要先在其父视图中释放才能添加到另一个父视图

第二种是说:初始化时使用inflater可能出现异常

View result = inflater.inflate(R.layout.customer_layout, container);

改成下面就可以了,大概意思是不将container作为新创建的view的父视图。
View result = inflater.inflate(R.layout.customer_layout, container, false);
 
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:3562)
at android.view.ViewGroup.addView(ViewGroup.java:3415)
at android.support.v4.view.ViewPager.addView(ViewPager.java:1341)
at android.view.ViewGroup.addView(ViewGroup.java:3360)
at android.view.ViewGroup.addView(ViewGroup.java:3336)
at com.atguigu.beijingnews2.newseconddetailpager.SecondDetailPager$2.instantiateItem(SecondDetailPager.java:69)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:869)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1085)
at android.support.v4.view.ViewPager.populate(ViewPager.java:951)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:250)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:543)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5045)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

最后是我的错误代码:重复将同一个imageView添加到container中也不可以,也属于将一个view对象设置了两个父视图。

解决方案是将ImageView imageView = new ImageView(activity);挪到instantiateItem()中,即创建多个对象就可以了。

    ImageView imageView = new ImageView(activity);
      @Override
public Object instantiateItem(ViewGroup container, int position) {
x.image().bind(imageView, topimageUris.get(position));
imageViews.add(imageView);
container.addView(imageViews.get(position));
return imageViews.get(position);
}

异常java.lang.IllegalStateException的解决的更多相关文章

  1. 项目启动异常,java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

    java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' befo ...

  2. 使用Servlet3.0新特性asyncSupported=true时抛异常java.lang.IllegalStateException: Not supported

    最近在运用Servlet3.0新特性:异步处理功能的时候出现以下了2个问题: 运行时会抛出以下两种异常: 一月 19, 2014 3:07:07 下午 org.apache.catalina.core ...

  3. Tomcat启动之异常java.lang.IllegalStateException

    严重: Exception sending context destroyed event to listener instance of class org.springframework.web. ...

  4. 常见的java异常——java.lang.IllegalStateException: Ambiguous handler methods mapped for HTTP path

    此异常是由于你的controller中有两个名字与内容相同的方法: 出现此异常时去检查你的controller中是否有重复的名字的方法:

  5. Tomcat上java.lang.IllegalStateException: Optional int parameter 'id' is not present

    今日, 本人在tomcat+spring mvc平台的服务器上遇到java.lang.IllegalStateException: Optional int parameter 'id' is not ...

  6. java.lang.IllegalStateException: Connection pool shut down

    最近使用HttpClient 4.5 使用 CloseableHttpClient 发起连接后,使用CloseableHttpResponse 接受返回结果,结果就报错了,上网查了下,有位stacko ...

  7. maven单元测试报java.lang.IllegalStateException: Failed to load ApplicationContext

    报这个异常java.lang.IllegalStateException: Failed to load ApplicationContext的时候,通常是因为applicationContent.x ...

  8. java.lang.IllegalStateException: Fragment bb{42261900} not attached to Activity

    A.处理异常java.lang.IllegalStateException: Fragment bb{42261900} not attached to Activity处理方式:由于在线程中调用Fr ...

  9. response.sendRedirect 报 java.lang.IllegalStateException 异常的解决思路

    今天在进行代码开发的时候,出现了 java.lang.IllegalStateException异常,response.sendRedirect("./DEFAULT.html") ...

随机推荐

  1. Qt部件--烧肉

    1,QSplitter

  2. Python字符串与数字拼接

    Python不像JS或者PHP这种弱类型语言里在字符串连接时会自动转换类型,而是直接报错.要解决这个方法只有提前把int转成string,然后再拼接字符串即可. 如代码: 1 2 3 4 5 # co ...

  3. VirtualBox详细教程

    转自:http://bbs.kafan.cn/thread-358294-1-1.html 1.Sun xVM VirtualBox简介 VirtualBox官方网站:http://www.virtu ...

  4. Win7下unetbootin-windows-585工具制作Ubuntu12.04 U盘启动盘

    1.下载unetbootin-windows-585工具,网址如下: unetbootin-windows-585 2.unetbootin-windows-585制作U盘启动盘 准备好1个4G的U盘 ...

  5. js中调用mangeto的js翻译

    第一步: <script type="text/javascript"> Translator.add('英文','<?php echo this->__( ...

  6. 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)

    前言 为了保证每周一篇的进度,又由于Vitamio新版本没有发布, 决定推迟本地播放的一些功能(截图.视频时间.尺寸等),跳过直接写在线播放部分的章节.从Vitamio的介绍可以看得出,其支持http ...

  7. Net常用命名空间和类介绍

    一.基础命名空间 l  System.Collections 包含了一些与集合相关的类型,比如列表,队列,位数组,哈希表和字典等. l  System.IO 包含了一些数据流类型并提供了文件和目录同步 ...

  8. SQL Server数据库---》基础

    SQL Server:只是操作数据库的一个工具(这种工具,只是提供一个界面化的方式让用户方便操作数据库) 开启服务:点击:我的电脑(计算机)--管理--服务和应用程序--服务--开启SQL Serve ...

  9. sqlserver事务与回滚

    如果要在Production执行数据改动必须小心,可以使用事务提前验证一下自己写的SQL是不是你期望的.尤其是Update的where 条件有问题的话,跟新的记录就会超出预期的范围.如下面的语句,一着 ...

  10. sqlplus查看服务名

    查看服务名: show parameter service 查看实例名: select * from v$instance; 查看数据库名: select name from v$database; ...