Saturday, June 7, 2014

Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment

I was using Google map API version2 with for one of my application.In layout I was using "com.google.android.gms.maps.MapFragment".

 <RelativeLayout
                        android:id="@+id/relative_disc_nyc_map"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent" >

                        <fragment
                            android:id="@+id/frg_disc_nyc_map"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            class="com.google.android.gms.maps.MapFragment" />
             </RelativeLayout>

And while executing I was using the above layout and adding it into fragment.....

public class DiscoverNYCActivity extends Fragment {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_discover_nyc, container, false);
        lbl_poi_title = (TextView) rootView.findViewById(R.id.lbl_poi_title);
        lbl_rate_count = (TextView) rootView.findViewById(R.id.lbl_rate_count);
return rootView;
}

But when I was travesing to the sam e screen twice.I was giving me below error

06-07 14:41:41.496: E/AndroidRuntime(21037): FATAL EXCEPTION: main
06-07 14:41:41.496: E/AndroidRuntime(21037): android.view.InflateException: Binary XML file line #120: Error inflating class fragment
06-07 14:41:41.496: E/AndroidRuntime(21037): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
06-07 14:41:41.496: E/AndroidRuntime(21037): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
06-07 14:41:41.496: E/AndroidRuntime(21037): at com.wf.wholesale.nymta.DiscoverNYCActivity.onCreateView(DiscoverNYCActivity.java:101)
06-07 14:41:41.496: E/AndroidRuntime(21037): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
06-07 14:41:41.496: E/AndroidRuntime(21037): Caused by: java.lang.IllegalArgumentException: Binary XML file line #120: Duplicate id 0x7f090058, tag null, or parent id 0x7f090057 with another fragment for com.google.android.gms.maps.MapFragment
06-07 14:41:41.496: E/AndroidRuntime(21037): at android.app.Activity.onCreateView(Activity.java:4971)
06-07 14:41:41.496: E/AndroidRuntime(21037): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:695)
06-07 14:41:41.496: E/AndroidRuntime(21037): ... 24 more


The problem is that what I was trying was wrong. You shouldn't be inflating fragments inside other fragments. From Android's documentation:

Note: You cannot inflate a layout into a fragment when that layout includes a <fragment>. Nested fragments are only supported when added to a fragment dynamically.

I have resolved the error with below changes.....

public class DiscoverNYCActivity extends Fragment {
View rootView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 if (rootView != null) {
           ViewGroup parent = (ViewGroup) rootView.getParent();
           if (parent != null)
               parent.removeView(rootView);
       }
       try {
        rootView = inflater.inflate(R.layout.activity_discover_nyc, container, false);
       } catch (InflateException e) {
            map is already there, just return view as it is 
       }
        lbl_poi_title = (TextView) rootView.findViewById(R.id.lbl_poi_title);
        lbl_rate_count = (TextView) rootView.findViewById(R.id.lbl_rate_count);
return rootView;
}

15 comments:

  1. You can use mapView instead of fragment (for map) cause android don't permit you to add fragment as a child of a fragment.
    Another alternative way is , In onPause callback you can remove the Maps fragment.

    ReplyDelete
    Replies
    1. If you run the map and modify it with the method you say, the map will restart and even if you get the buttons will return these. The method explained here helps keep the changes and is intended for use by other fragments.

      Thank you very much for sharing

      Delete
  2. the ACM Awards for the 15th time, but even with all of her experience, she still isn't willing

    to pick who she thinks will walk home with a trophy. ACM Awards 2019 Live via live ACM Awards 2019 Live StreamI can't say in that category

    who is going to win. They're all my friends. I'm pulling for all of them. ACM Awards 2019 Live Streaming The Oklahoma native

    does share one challenging part of hosting the live televised broadcast – and it isn't

    entertaining millions of people watching at home. ACM

    Awards 2019 Live Stream
    Once McEntire's stylist gave the go-ahead, McEntire jumped on board

    to host the ACM Awards another year. But while the multiple wardrobe changes might be

    troublesome, that's not the part that gives her a touch of anxiety. ACM Awards 2019 Live The 2019 ACM Awards will air live from the MGM Grand

    Garden Arena in Las Vegas on Sunday, April 7, at 8 p.m. ET on CBS.

    ReplyDelete
  3. Is your Binance account got hacked and you have no solution to fix them instantly? Binance account hacking issues are quite obvious and users get into them despite having numerous errors. If you are having trouble due to Binance account hacking error, you can always talk to the team of skilled professionals via calling on Binance customer service number which is functional all the time. Feel free to speak to the team to Binance Support Number get desired and impeccable results in no time. You can always contact to the team and get fruitful remedies from the team who is always punctual and helpful.

    ReplyDelete
  4. Are you facing issues due to Gemini two-factor authentication? Is it hampering the work and growth of your account? If you don’t know how to deal with such errors and you are looking for solutions to deal with them, you can always call on Gemini phone number which is always Gemini Support Number functional. You can contact the team anytime and get desired results in no time. The team is always there to help you out and makes sure to provide solutions that are easy to execute. Connect with the team to avail perfect and instant solutions. You can talk to them at anytime as they work 24/7 for their users .

    ReplyDelete
  5. Errors occurrence while working on Binance exchange is understood. There are numerous errors like login errors, password errors, installation errors and much more, which are faced by the users on daily basis. If you want to fix those errors, you can always get in touch with the proficient professionals by dialing Binance support number which is available 24/7. The customer Binance Support Number executive to the user's query patiently and provide those solutions which are easy to implement. Get the best-suited solutions and techniques from the experts. They feel delighted to help you at every possible step.

    ReplyDelete
  6. Blockchain account hacking or Blockchain customer care +1 (855) 942-0545 United States losing access to account due to hacking is quite common these days. If you ever get sceptical about anything in your account or your account is not working properly, you can always ask for help from the team who has years Blockchain Customer Service Number of experience and can handle all troubles in no time. Deal with these queries by taking guidance from them by calling on Blockchain customer care number which is always functional and the team knows how to assist at every step.

    ReplyDelete
  7. Sometimes newcomers who are using the Binance exchange for the first time get into sign-up errors which are difficult to deal by them. If you ever get stuck in such errors and need Binance Customer Service Number immediate assistance, you can always take help from the team of elite professionals who are there to guide you. Call on Binance customer service number which is functional and the team is ready to guide you. Reaching them is the best part as it helps in saving your time and you can directly approach them for dealing with problems.

    ReplyDelete
  8. Are you one of those users who have experienced hacking attempts in their Blockchain ? Blockchain has been victim of hacking events in the past for several times. If you are looking for ways to handle all troubles and need guidance, you can always Blockchain Customer Service Number have conversation with the team of elite professionals who are there to handle your worries. If you can contact the team via calling on Blockchain customer service number which is always functional and the team is ready to handle all your worries in fraction of time. Reach them to avail best-fit solutions in fraction of time.

    ReplyDelete