在初始化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. Android TextView文字描边的实现!!

    Android开发:文字描边 转自:http://www.oschina.net/code/snippet_586849_37287 1. [代码][Java]代码 1 2 3 4 5 6 7 8 9 ...

  2. SQL server指定随机数范围

    declare @randnum int=0declare @startnum int =0declare @endnum int=0 set @startnum = 150 set @endnum ...

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

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

  4. bootstrapvalidator之API学习

    最近项目用到了bootstrap框架,其中前端用的校验,采用的是bootstrapvalidator插件,也是非常强大的一款插件.我这里用的是0.5.2版本.下面记录一下使用中学习到的相关API,不定 ...

  5. Android 支付宝接入时常见的问题

    1.概述 首先说明下,Android支付宝接入用的是快捷支付,下载地址是https://b.alipay.com/order/techService.htm    支付宝移动接入地址https://b ...

  6. OC中另外的一个常用技术:通知(Notification)

    OC中另外的一个常用技术:通知(Nofitication)其实这里的通知和之前说到的KVO功能很想,也是用于监听操作的,但是和KVO不同的是,KVO只用来监听属性值的变化,这个发送监听的操作是系统控制 ...

  7. Java语言导学笔记 Chapter 9 IO

    java.io 9.1.1 字符流 Reader为读取器(reader)提供API和部分实现,读取器是读取16位字符的流: Writer为写出器(writer)提供API和部分实现,写出器是写16位字 ...

  8. 深度解析Linux通过日志反查入侵

    有一个朋友的服务器发现有入侵的痕迹后来处理解决但是由于对方把日志都清理了无疑给排查工作增加了许多难度.刚好手里有些资料我就整理整理贴出来分享一下.其实日志的作用是非常大的.学会使用通过日志来排查解决我 ...

  9. 怎样在Eclipse中使用debug模式调试程序

    最基本的操作是: 1, 首先在一个java文件中设断点,然后运行,当程序走到断点处就会转到debug视图下, 2, F5键与F6键均为单步调试,F5是step into,也就是进入本行代码中执行,F6 ...

  10. llinuxs介绍与常用命令

    一.Linux系统概述1.计算机资源软件资源硬件资源操作系统2.操作系统WindowsMacOSLinuxUnix3.Linux含义狭义Linux:由Linus一段内核代码广义Linux:Linux厂 ...