Android Basics _ Some errors when learning fragment [Blog Park]

Source: Internet
Author: User

 
   
  
  1. 2015年6月7日09:47:12
  2. 早晨起来把昨天的NewsFragment小小的Project错误找到了
Null pointer exception
    • Cause: Because you have encountered this null pointer exception error before, most of the reason is because the object or array is created but not instantiated, only an object reference or an array reference is defined, and then the method to invoke the object or to pass the data to the elements of the array;
    • This is because:
      • Many controls are defined for global variables, but are not initialized in methods-see the Java Programming Idea-instantiation Chapter
      • The list collection is defined when the corresponding adapter is bound to the ListView control, but sometimes it is forgotten to instantiate the list collection, such as writing a private list fragments, and then directly calling the. Add () method, must be an error.
Java.lang.IllegalStateException:The specified child already have a parent. You must call Removeview () on the child ' s parent first.
    • Because you need to decide if you want to return to the parent layout when you convert the layout to view, this is because I forgot to write false, Pit Daddy! Which means I only wrote this View iew=view.inflate (R.layout.frag_culture,container);
    • View view=view.inflate (R.layout.frag_culture,container,false);
    • I have always wanted to know how to call the ListView in fragment, because there is a problem, is the first parameter context parameter settings, before the activity is directly activity.this can be, Now to fragment do not know how to do, but just to learn fragment and activity transfer data, and before and classmates discussed, all the data fragment finally will and an activity bound ... So that's how it's done.
Implicit super constructor Fragmentpageradapter () is undefined. Must explicitly invoke another constructor


Call requires API level one (current min is 8)
    • The required API version is 11, which is now 8
    • Solution: Modify the Manifiest.xml in the


The method Add (Fragment) in the type List was not applicable for the arguments
    • The parameter type in the Add (Fragment) method does not match the type of the parameter in the list
    • In other words, the parameter in the list shown is fragment is the android.app.Fragment type, but Newsfragment StoryFragment is extends ANDROID.SUPPORT.V4 package Under the fragment
    • That is, the parameter types do not match, you need to change the parameter type to the same, I will change the list of fragment to the ANDROID.SUPPORT.V4 package under the fragment type
    • Knowledge point is a collection generic in the Java Foundation
    • Binary XML file Line:error inflating class
    • Failed to load layout file
    • Solution: Because Viewpager really android.support.v4.view.ViewPager in, but I wrote Android.support.v4.app.ViewPager also wrote Appp ... Have no words, carelessness, to look at the log file more
    • You can find the correct file path in the Android.support.v4.jar package, be sure to write the right



From for notes (Wiz)

Android Basics _ Some errors when learning fragment [Blog Park]

Related Article

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.