I tried 2 different AppcompatButtons and normal Button in xml, but I get the same error.
Its a googlemap i just want search a city and i will go the city location
Method 1
<androidx.appcompat.widget.AppCompatButton
app:layout_constraintLeft_toRightOf="@+id/sv_location"
android:id="@+id/startBtn"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:onClick="startBtn"
android:text="add"
tools:ignore="MissingConstraints" />
Method 2
<Button
app:layout_constraintLeft_toRightOf="@+id/sv_location"
android:id="@+id/startBtn"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:onClick="startBtn"
android:text="add"
tools:ignore="MissingConstraints" />
iam using a searchview in button oncllick
fun startBtn(view: View){
val searchView:SearchView =view.findViewById<SearchView>(R.id.sv_location)
lateinit var location: String
location = searchView.query.toString()
var addressList: List<Address>? = null
if (location == null || location == "") {
Toast.makeText(requireContext(),"provide location",Toast.LENGTH_SHORT).show()
}
else{
val geoCoder = Geocoder(requireContext())
try {
addressList = geoCoder.getFromLocationName(location, 1)
} catch (e: IOException) {
e.printStackTrace()
}
val addresss = addressList!![0]
val latLng = LatLng(addresss.latitude, addresss.longitude)
nMap!!.addMarker(MarkerOptions().position(latLng).title(location))
nMap!!.animateCamera(CameraUpdateFactory.newLatLng(latLng))
Toast.makeText(requireContext(), addresss.latitude.toString() + " " + addresss.longitude, Toast.LENGTH_LONG).show()
}
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener{
override fun onQueryTextSubmit(p0: String?): Boolean {
searchView.clearFocus()
return false
}
override fun onQueryTextChange(p0: String?): Boolean {
TODO("Not yet implemented")
return false
}
})
}
Fails image you cant see the exception from this link
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…