Google support Map crashing - android

Google SupportMapFragment is crashing when executing this
( (SupportMapFragment)getChildFragmentManager().findFragmentById(
R.id.map)).getMapAsync(googleMap -> presenter.onMapReady(googleMap, getContext()));
with the nullpointer and the stacktrace is:
java.lang.NullPointerException: Attempt to invoke virtual method 'int
android.graphics.Bitmap.getWidth()' on a null object reference
at com.google.maps.api.android.lib6.gmm6.vector.gl.aj.b(:com.google.android.gms.dynamite_mapsdynamite#214516081#21.45.16
(150400-0):2)
at com.google.maps.api.android.lib6.gmm6.vector.gl.aj.(:com.google.android.gms.dynamite_mapsdynamite#214516081#21.45.16
(150400-0):2)
at com.google.maps.api.android.lib6.gmm6.vector.gl.g.(:com.google.android.gms.dynamite_mapsdynamite#214516081#21.45.16
(150400-0):18)
at com.google.maps.api.android.lib6.gmm6.vector.bs.d(:com.google.android.gms.dynamite_mapsdynamite#214516081#21.45.16
(150400-0):14)
at com.google.maps.api.android.lib6.gmm6.vector.av.run(:com.google.android.gms.dynamite_mapsdynamite#214516081#21.45.16
(150400-0):44)
xml for the supportfragment is
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />

It looks like Google Map issue. Clearing the app cache helps me.

Related

My App is Crashing while using google maps in my flutter application

Here is the error while crashing:-
Process: com.example.basic_setup, PID: 13613
java.lang.NullPointerException: Attempt to get length of null array
at java.nio.ByteBufferAsIntBuffer.put(ByteBufferAsIntBuffer.java:122)
at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.i(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):2)
at com.google.maps.api.android.lib6.gmm6.vector.gl.buffer.n.d(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):3)
at com.google.maps.api.android.lib6.gmm6.vector.gl.drawable.d.s(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):2)
at com.google.maps.api.android.lib6.gmm6.vector.gl.drawable.ao.s(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):12)
at com.google.maps.api.android.lib6.gmm6.vector.bz.s(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):29)
at com.google.maps.api.android.lib6.gmm6.vector.bs.b(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):151)
at com.google.maps.api.android.lib6.gmm6.vector.av.run(:com.google.android.gms.dynamite_mapsdynamite#223017097#22.30.17 (190400-0):48)
I am getting error while navigating fastly from another screen to map screen in bottom navigation bar.
this is the known issue in map v2:
https://issuetracker.google.com/issues/35829536
Use SupportMapFragment in xml file instead of mapview. eg :
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
for more infmormation follow these links :
https://developers.google.com/android/reference/com/google/android/gms/maps/SupportMapFragment
https://developers.google.com/maps/documentation/android-api/map

cannot cast androidx.fragment.app.Fragment to com.google.android.youtube.player.YouTubePlayerFragment

I am using YoutubePlayerView in fragment but when i am getting the reference of youtubeplayerview from my fragment then i am getting the error of inconvertible types. Can anyone tell me that whats wrong i am doing?
Here is my layout.xml file:
<fragment
android:id="#+id/youtube_frag"
android:name="com.google.android.youtube.player.YouTubePlayerFragment"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
/>
Fragment.class:
myouTubePlayerView= (YouTubePlayerFragment)getFragmentManager().findFragmentById(R.id.youtube_frag);
in this line i am getting error that cannot cast fragment into youtubeplayerfragment. Please help me.
Checkout this link Youtube player support fragment no longer working on Android studio 3.2 (androidx)

Kotlin Direct Access XML Error on clicking ImageView

I have the current working code, which add
mNavigationView = findViewById(R.id.navigation)
mDrawerLayout = findViewById(R.id.drawerLayout)
val headerview : View = mNavigationView.getHeaderView(0)
mSettingsIcon = headerview.findViewById(R.id.settingsIcon)
mSettingsIcon.setOnClickListener {
// navigate other activity
}
I want to replace it using direct XML access that is available on Kotlin.
I tried the following:
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.navigation_header.*
mSettingsIcon.setOnClickListener {
// Handle Click
}
But I received the following error:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.my.app/com.my.app.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference (...) Caused by:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.ImageButton.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
I think that is because the ImageView Settings is located inside another XML (called Navigation Header) that is on XML like this:
inside activity_main.xml:
<com.google.android.material.navigation.NavigationView
android:id="#+id/mNavigationTab"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/navigation_header"
app:menu="#layout/navigation_items"/>
inside navigation_header.xml:
<ImageButton
android:id="#+id/mSettingsIcon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/icon_settings"
android:layout_marginTop="10sp"
android:layout_marginStart="20sp"
android:padding="0dp"/>
Does anyone knows how can I access using Kotlin direct access to XML components?
At first, You have to get HeaderView from NavigationView and then use below code to achieve this:
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.navigation_header.view.*
val headerView = mNavigationTab.getHeaderView(0)
headerView.mSettingsIcon.setOnClickListener {
// Handle Click
}

GoogleMap complains of being a null object reference

I am working on an android application where I use maps and this is the error that I am getting
Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setMapType(int)' on a null object reference
Prior to posting my query here I have looked for other similar issues but my code already have all what is being suggested so I was hoping if someone could point out the error.
This is the line which throws the error(second line).
I have no idea why it is caling map null when I've assigned it (at least I think I have)
private void initViews() {
map = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
//map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
and also this is my xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="65dp" >
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Use getMapAsync(...) instead of getMap().
Example can be found here.

RequestFactory validation fails when including Android maps v2 fragment

I have successfully used RequestFactory for a very long time in my Android app, but now when trying to upgrade to maps v2, when I include
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
in my XML layout file, I get the error:
01-25 08:08:41.978: E/AndroidRuntime(19854):
java.lang.RuntimeException: Unable to resume activity{com.xx/com.xx.MyActivity}:
java.lang.RuntimeException: The RequestFactory ValidationTool must be
run for the com.xx.client.MyRequestFactory RequestFactory type
If I remove the fragment code from the layout XML file everything works fine.
How does this fragment affect my RequestFactory validation and how can I fix it?
Thanks.
As pointed out in How to Use the GWT-RequestFactory in Android SyncAdapter (always getting ValidationTool-Error)
if one adds
Thread.currentThread().setContextClassLoader(mContext.getClassLoader());
before
requestFactory = RequestFactorySource.create(factoryClass);
the problem is fixed.

Categories

Resources