The solution of abnormal java.lang.IllegalStateException

Source: Internet
Author: User

When initializing Viewpageradapter, an exception is displayed. I looked it up from the Internet. There are two types of questions, one of which is to set up two parent classes for a view, such as:

TextView TV = new TextView ();
Layout.adview (TV);
Layout2.adview (TV); This will report an exception that needs to be released in its parent view before it can be added to another parent view

The second is that the use of inflater may occur when initializing

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

改成下面就可以了,大概意思是不将container作为新创建的view的父视图。
  view result = Inflater. (r. Layout. Customer_layout, Container,false           
 

Java.lang.IllegalStateException:The specified child already have 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.newseconddetailp Ager.     Seconddetailpager$2.instantiateitem (seconddetailpager.java:69)                                                                         At Android.support.v4.view.ViewPager.addNewItem (V iewpager.java:869) at Android.support.v4.view . Viewpager.populate (viewpager.java:1085) at an                                                                              Droid.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 (C horeographer.java:543)                                                                             At Android.view.choreographer$framedisplayeve Ntreceiver.run (choreographer.java:747) at and                                                                              Roid.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 Me Thod)

And finally, my error code: It is not possible to add the same imageview to container again, or to set a View object to two parent views.

The solution is to ImageView ImageView = new ImageView (activity); Move to Instantiateitem (), that is, to create multiple objects.

1 ImageView ImageView = new ImageView (activity); 
@Override
2 PublicObject Instantiateitem (ViewGroup container,intposition) {3 4X.image (). Bind (ImageView, Topimageuris.Get(position));5 Imageviews.add (imageView);6Container.addview (imageviews.Get(position));7 returnImageviews.Get(position);8}

The solution of abnormal java.lang.IllegalStateException

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.