在初始化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. poj3077---进位

    #include <stdio.h> #include <stdlib.h> #include<string.h> ]; ]; int main() { int n ...

  2. AndroidUI 视图动画-移动动画效果 (TranslateAnimation)

    移动动画效果可以使用 TranslateAnimation; <Button android:id="@+id/btnTranslate1" android:layout_w ...

  3. (转)iOS开发ARC内存管理技术要点

    转自:http://www.cnblogs.com/flyFreeZn/p/4264220.html 本文来源于我个人的ARC学习笔记,旨在通过简明扼要的方式总结出iOS开发中ARC(Automati ...

  4. 任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0。

    题目:任意给定一个正整数N,求一个最小的正整数M(M>1),使得N*M的十进制表示形式里只含有1和0. 解法一:暴力求解.从1开始查找M,然后判断M*N=X这个数字是否只含有0,1. 解法二:由 ...

  5. C++ 矩阵乘法

    //构造矩阵类,重载乘法操作符 //作者:nuaazdh //时间:2011年12月1日 #include <iostream> using namespace std; //Matrix ...

  6. VS中,无法嵌入互操作类型“……”,请改用适用的接口的解决方法

    最近使用VS,在引用COM组件的时候,出现了无法嵌入互操作类型“……”,请改用适用的接口的错误提示.查阅资料,找到解决方案,记录如下: 选中项目中引入的dll,鼠标右键,选择属性,把“嵌入互操作类型” ...

  7. Android入门——UI(9)

    SwipRefreshLayout下拉刷新控件 <?xml version="1.0" encoding="utf-8"?> <android ...

  8. json(转)

    转自:http://www.cnblogs.com/mcgrady/archive/2013/06/08/3127781.html 阅读目录 JSON的两种结构 认识JSON字符串 在JS中如何使用J ...

  9. java中int和Integer的区别

    Integer与int的种种比较你知道多少?  转载自http://www.cnblogs.com/liuling/archive/2013/05/05/intAndInteger.html 如果面试 ...

  10. nginx log format

    参数 说明 示例 $remote_addr 客户端地址 211.28.65.253 $remote_user 客户端用户名称 -- $time_local 访问时间和时区 18/Jul/2012:17 ...