Map + fragment- The element 'LinearLayout' has invalid child element 'fragment'

Manu4uManu4u USMember
edited June 2016 in Xamarin.Android

I started learning Xamarin from few days, using Visual Studio 2015 IDE with Xamarin, lacking in knowledge, i am unable to solve this..

Working on Map Task, using fragment

Severity Code Description Project File Line Suppression State
Warning The element 'LinearLayout' has invalid child element 'fragment'. List of possible elements expected: 'GLSurfaceView, AdapterView, AdapterViewAnimator, AutoCompleteTextView, MediaController, TextView, FragmentBreadCrumbs, AppWidgetHostView, GestureOverlayView, ExtractEditText, KeyboardView, RSSurfaceView, RSTextureView, SurfaceView, TextureView, ViewGroup, ViewStub, WebView, AbsListView, AbsSeekBar, AbsSpinner, AbsoluteLayout, AdapterViewFlipper, AnalogClock, Button, CalendarView, CheckBox, CheckedTextView, Chronometer, CompoundButton, DatePicker, DialerFilter, DigitalClock, EditText, ExpandableListView, FrameLayout, Gallery, GridLayout, GridView, HorizontalScrollView, ImageButton, ImageSwitcher, ImageView, LinearLayout, ListView, MultiAutoCompleteTextView, NumberPicker, ProgressBar, QuickContactBadge, RadioButton, RadioGroup, RatingBar, RelativeLayout, ScrollView, SearchView, SeekBar, SlidingDrawer, Space, Spinner, StackView, Switch, TabHost, TabWidget, TableLayout, TableRow, TextSwitcher, TimePicker, ToggleButton, TwoLineListItem, VideoView, ViewAnimator, ViewFlipper, ViewSwitcher, ZoomButton, ZoomControls'. googlemap C:\Users\googlemap\Resources\layout\Main.axml 6

or
if i build and trying to run.. i will get as below,

"Android.Views.InflateException:Binary XML file line #1: Error inflating class fragment.

and i added Xamarin.Android.Support.v4 and Xamarin.Android.Support.v7 but not getting.

the code as below..

Main.axml

<?xml version="1.0" encoding="utf-8"?>

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

Activity.cs

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Gms.Maps;
using Android.Gms.Maps.Model;

namespace googlemap
{
[Activity(Label = "googlemap", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, IOnMapReadyCallback
{

    private GoogleMap GMap;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        SetUpMap();
    }

    private void SetUpMap()
    {
        if (GMap == null)
        {
           FragmentManager.FindFragmentById<MapFragment>(Resource.Id.googlemap).GetMapAsync(this);

        }
    }
    public void OnMapReady(GoogleMap googleMap)
    {
        this.GMap = googleMap;
        GMap.UiSettings.ZoomControlsEnabled = true;



        LatLng latlng = new LatLng(Convert.ToDouble(13.0291), Convert.ToDouble(80.2083));
        CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latlng, 15);
        GMap.MoveCamera(camera);


        MarkerOptions options = new MarkerOptions()
                    .SetPosition(latlng)
                    .SetTitle("Chennai");

        GMap.AddMarker(options);

    }

}

}

Android Manifest file

<?xml version="1.0" encoding="utf-8"?>











Posts

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello @Manu4u

    i'm not too an expert with mobile dev but for me is nice ...
    perhpas be sure you are not and invalid character in the layout ?

    in your sample you put well in the mane of the fragment => com.google.....

    If i was you, i made a new blank project you can draw a map in 5 minute i think when you have the right manifest and your api key.

    if begin to draw maps since one week and there are a lot of sample on youtube

    hope this help

  • Manu4uManu4u USMember

    thank you some much @Christophe BERNARD,

    I tried the above video too.. same Error which i am getting, i tried many ways.. pls help me

  • Manu4uManu4u USMember

    pls find the attach screens

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello @Manu4u
    i see enough strange could you send me a mail at this address tapastoutvu@hotmail.com i will send you a zip files contains my sample (just a sample map card) you must just change the key and package name

    if => it's work => i don't know what happen's on your pc
    else => if you have the same error => remove visual studio 2015 delete all folder and install again ...

    i've buy a new pc last week and i have install visual studio community and build a sample map without problem ...

    have a nice day

  • Manu4uManu4u USMember

    thank you so much for your reply..

    mail sent..
    and my PC is quite good i7 Intel 16GB Ram
    and sure i will try to re install but it takes much time i guess but i will do it as per your instructions

    pls find 2 more screens..

    1.png 78.7K
    2.png 85.1K
  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello again @Manu4u , i see on the screen the error and for me i can't understand what really happens PERHPAS try to make a new project but WITHOUT name google, maps or any word reserved by google or maps ...

    perhpas some mistmatch ...

    it's not possible to upload my package in the cloud i don't know why and of course not possible to send a mail with attachament > 40 mega !

    i've send you one / two mail => the one is fail but after i've receive a notification that the message was send !!!!!
    well, if you receive to mail there are in the two mail the same thing all my code, layout, manifest, main activity and other class

    hope this help guy

  • Manu4uManu4u USMember

    thank you so much for your reply,

    Sure i will work on it.. let you know..

  • Manu4uManu4u USMember

    I just pasted the code, but again the same...

    finally i think i should reinstall whole setup as you said..

    3.png 81.4K
  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    @Manu4u do you receive my code ?
    if yes try just to place my code into your project ...

    if error continue , yes i think you must to remove vs 2015 and don't forget to delete all folder in visual studio 14 in program files be sure all is deleded before to install again ...

    keept the power :)

  • Manu4uManu4u USMember

    yeah thank you today i will do it.. and let you know regarding this today..

  • Manu4uManu4u USMember

    I have one question can i do repair ? reinstall of visual studio takes 20 Hours

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    it's not the first time i have some problem with vs 2015 community and xamarin and as i said no solution found on internet ...
    me, i have uninstall all

    • visual studio
    • sdk java
    • ...

    take more 4h perhpas but after all is installed and Ok (after tested => because one time each time i create a project i receive a message create project failed )

    after all is ready and ok i've make an image of my pc in case of :) :)

    pretty hard i know

  • Manu4uManu4u USMember

    i tried but No Use.. i did reinstall of the VS 2015, same error...

  • ChristopheBERNARDChristopheBERNARD BEMember ✭✭✭✭

    Hello @Manu4u ,
    ahhh ... did you remove too sdk java and delete all folders after remove them ?

    if yes => sorry i don't know as i said sometimes and i don't know why my environnement doesn't work and it's impossible to find a solution on internet ...

    my solution is to remove all (vs 2015, java sdk, delete all folders) and re install all ...

    Ok it's take time => more 4h i think but it's the only solution i've found until now ...

    try again ...

  • antonmeserantonmeser USMember

    I have the same error
    Any new solutions?

  • any luck with this? I am getting the same error. i am trying to show the map on one of my activity pages in the application but fragment is not recognized in the layout.

  • PareshSukhiyaPareshSukhiya USMember ✭✭
    edited September 12

    I'm Getting the error when i try to include android.support.v7.widget.Toolbar inside the linear layout tag
    in the .axml file

Sign In or Register to comment.