1

I keep getting an error on the line for the support map fragment, i am new to android and java so, do not have the answers it's saying ';' is expected, but once inserted before the get child fragment manager, it makes the support map fragment unreachable and I get an error across the whole line.

here is my class

package com.example.hp_user.shoutfinal28;


import android.app.FragmentManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;


public class FragmentShouts_Maps extends Fragment implements OnMapReadyCallback {


public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Get the view from fragment shouts.xml
    View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
    return view;

    SupportMapFragment fragment = SupportMapFragment.newInstance(); getChildFragmentManager().findFragmentById(R.id.maps);
    fragment.getMapAsync(this);
}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);




}

@Override
public void onMapReady (GoogleMap googleMap) {

}



}

here is my xml file

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment android:id="@+id/maps"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.example.hp_user.shoutfinal28.FragmentShouts_Maps"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_alignParentEnd="true">
</fragment>

</RelativeLayout>
Aman.V
  • 23
  • 5

1 Answers1

2

Replace this code:

View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
return view;
SupportMapFragment fragment = SupportMapFragment.newInstance(); getChildFragmentManager().findFragmentById(R.id.maps);
fragment.getMapAsync(this);

with this:

View view = inflater.inflate(R.layout.fragmentshouts_maps, container, false);
SupportMapFragment fragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.maps);
if (fragment!= null) {
    fragment.getMapAsync(this);
}
return view;

You don't need to create a new fragment. You only need a reference to your map you have already placed in your xml. Secondly return line is always the the last line of the function. Because once the return line is executed, remaining lines of the method is always skipped.

Rehan
  • 3,270
  • 5
  • 31
  • 30