The Annex departs from NullPointerException on the MapFragment emulsion



  • There was a need to integrate the Google card into the project, tossed the Google MapFragment, to this point there was no google, checked on the phone last night (Samsung Galaxy S4), fragmented and accurately displayed the map. GoogleMaps API on google is activated, the key Api is in the manifest. Activity in which fragments are launched is inherited from AppCompatActivity. In an attempt to move to a fragment with a map in built-in emulsion (Nexus 4 21 API(with GoogleAPIs) and Nexus 4 23 API(with GoogleAPIs), the annex is flying.

    Question: What can be done to get a piece of maps to launch correctly and display maps at the emulsion?

    I'm adding stats of error, full code of fragment, and partly layates, manifest and Build.gradle.

    Scattering errors:

    12-07 11:15:09.290 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.290 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.290 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.290 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.290 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.290 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.300 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.300 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.300 2318-2318/xx.xxx.xxx W/GooglePlayServicesUtil: Google Play services out of date.  Requires 8298000 but found 8185480
    12-07 11:15:09.320 2318-2318/xx.xxx.xxx D/AndroidRuntime: Shutting down VM
    12-07 11:15:09.320 2318-2318/xx.xxx.xxx E/ACRA: ACRA caught a NullPointerException for xx.xxx.xxx
                                                            java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.MapFragment.getMapAsync(com.google.android.gms.maps.OnMapReadyCallback)' on a null object reference
                                                                at xx.xxx.xxx.courier.OrdersFragmentMap.onCreateView(OrdersFragmentMap.java:45)
                                                                at android.app.Fragment.performCreateView(Fragment.java:2220)
                                                                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)
                                                                at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)
                                                                at android.app.BackStackRecord.run(BackStackRecord.java:793)
                                                                at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)
                                                                at android.app.FragmentManagerImpl$1.run(FragmentManager.java:482)
                                                                at android.os.Handler.handleCallback(Handler.java:739)
                                                                at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                at android.os.Looper.loop(Looper.java:148)
                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    

    Card fragment code:

    package xx.xxx.xxx.courier;
    import android.os.Bundle;
    import android.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.OnMapReadyCallback;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;
    import xx.xxx.xxx.R;
    

    public class OrdersFragmentMap extends Fragment implements OnMapReadyCallback {

    public static OrdersFragmentMap newInstance() { return  new OrdersFragmentMap(); }
    
    public OrdersFragmentMap() {  }
    
    @Override
    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.courier_fragment_map, container, false);
        MapFragment mapFragment = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        return view;
    }
    
    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng sydney = new LatLng(-33.867, 151.506);
    
        googleMap.setMyLocationEnabled(true);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
    
        googleMap.addMarker(new MarkerOptions().title("Sydney").snippet(
                "The most populous city in Australia.").position(sydney));
    
    }
    
    @Override
    public void onResume() {
        super.onResume();
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    
    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }
    

    }

    Layautcontaining MapFragment(fragment):

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment 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"
    android:id="@+id/map"
    tools:context="xx.xxx.xxx.CourierActivity"
    android:name="com.google.android.gms.maps.MapFragment"/>
    <!-- other elements -->
    </RelativeLayout>

    Manifest(fragment):

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xx.xxx.xxx" >

    &lt;permission
        android:name="com.example.demomap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" /&gt;
    &lt;uses-permission android:name="com.example.demomap.permission.MAPS_RECEIVE" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
    &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
    &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSRVICES" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
    

    <!-- To using maps -->
    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

    &lt;application
        android:name=".xxx"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_pink"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme" &gt;
        &lt;service android:name=".service.ServerService" /&gt;
        &lt;meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzaSy*****************VJifvg4M4"/&gt;
        &lt;meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" /&gt;
    
         &lt;!-- other elements --&gt;
    
    &lt;/application&gt;
    

    </manifest>

    Build.gradle(Papagment):

    dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.nbsp:library:1.01'
    compile 'info.hoang8f:android-segmented:1.0.6'
    compile 'ch.acra:acra:4.7.0-RC.3'
    compile 'com.google.android.gms:play-services-maps:8.3.0'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-auth:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
    compile 'com.google.android.gms:play-services:8.3.0'
    }



  • Decided the problem as follows. Firstly, the fragment class code changed so that the annex does not fly out on API 21 and above:

    public class OrdersFragmentMap extends Fragment
            implements OnMapReadyCallback, LoaderManager.LoaderCallbacks<Cursor> {
        ArrayList<Order> freeOrders =  new ArrayList<>();
        ArrayList<Order> myOrders = new ArrayList<>();
        private FragmentActivity myContext;
    
    public static OrdersFragmentMap newInstance() { return  new OrdersFragmentMap(); }
    
    public OrdersFragmentMap() {  }
    
    @Override
    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }
    
    
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.courier_fragment_map, container, false);
        FragmentManager fm = myContext.getSupportFragmentManager();
        SupportMapFragment mapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.map, mapFragment).commit();
        mapFragment.getMapAsync(this);
        return view;
    }
    
    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng sydney = new LatLng(-33.867, 151.506);
    
        googleMap.setMyLocationEnabled(true);
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
    
        googleMap.addMarker(new MarkerOptions().title("Sydney").snippet(
                "The most populous city in Australia.").position(sydney));
    }
    
    @Override
    public void onResume() {
        super.onResume();
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
    
    @Override
    public void onLowMemory() {
        super.onLowMemory();
    }
    
    @Override
    public void onAttach(Activity activity) {
        myContext=(FragmentActivity) activity;
        super.onAttach(activity);
    

    The method onAttach() is outdated and I use it temporarily only to launch android.support.v4.app.FragmentManager in AppCompatActivity.

    Second, a MapActivity template has been created, to do so, at the root of the project, to lick the right mice, to choose the new Gooogle MasterpsActivity. Of the three files established, only res/values/google_maps_api.xml(debug) copyed a link to generate the key that is in the commentary, moved it to the browser, created the key and earned everything. The strangest thing to do was put in the same counterpart and the name of the package. That's the thing.

    And on Galaxy S4 API was apparently working bypassing the Google protection, as there were no requests to the developer &apos; s console during the application.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2