SO I'm able to use MapFragment no issue but when I change it to supportMapFragment it bails out. with the below error. not sure what I'm doing wrong that one works and the other doesn't. The reason I need the support one is that I can't remove the fragment with when using mapfragment because the below line is expectin Fragment! and is receiving MapFragment.....so it fails...when I switch it to SupportMapFragment the below line works but the errors happen below.
Thanks
getFragmentManager().beginTransaction().remove(mapFragment).commit();
XML
<fragment
android:id="@+id/mapF"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="200dp" />
CLASS
import android.location.Address
import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.gms.maps.*
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import android.location.Geocoder
import android.text.Html
import android.webkit.WebView
import android.widget.Toast
import com.beust.klaxon.JsonObject
import com.beust.klaxon.Parser
import com.beust.klaxon.obj
import com.beust.klaxon.string
import com.github.kittinunf.fuel.httpGet
import com.github.kittinunf.fuel.httpPost
import com.github.kittinunf.result.Result
import com.github.kittinunf.result.getAs
import kotlinx.android.synthetic.main.fragment_1.view.*
import kotlinx.android.synthetic.main.fragment_event_details.*
import kotlinx.android.synthetic.main.fragment_event_details.view.*
import java.util.*
import kotlin.collections.ArrayList
class Event_details : Fragment(),OnMapReadyCallback{
lateinit var mMap:GoogleMap
lateinit var mWeb:WebView
lateinit var mapFragment:SupportMapFragment
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
var myView = inflater!!.inflate(R.layout.fragment_event_details, container, false)
var mP = Pair("news_id",101)
var mL:ArrayList<Pair<String,Int>> = ArrayList<Pair<String,Int>>()
mL.add(mP)
****do some JSON STUFF****
>>>>> LINNE 125 mapFragment = activity.supportFragmentManager.findFragmentById(R.id.mapF) as SupportMapFragment
mapFragment.getMapAsync(this)
return myView
}
ERROR
ntime: FATAL EXCEPTION: main Process: com.example.herbstzu.listview, PID: 11988 kotlin.TypeCastException: null cannot be cast to non-null type com.google.android.gms.maps.SupportMapFragment at com.example.sadfasdf.listview.Event_details.onCreateView(Event_details.kt:125) at android.support.v4.app.Fragment.performCreateView(Fragment.java:2354) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
SOLUTION
So...the solution was two fold....
When changing from MapFragment to SupportMapFragment.......
- Change XML class to SupportMapFragment in side of a fragment
- Change so that SupportMapFragment is a nullable throughout your code
- Change supportFragmentManager to childFragmentManager..supportFragmentManager will also work however it will not fire the onMapReady...
- Smile because you beat down Kotlin/Android like a little ..... ;)