Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Loads once and throws me away #13129

Closed
quimico99 opened this issue Oct 18, 2018 · 2 comments
Closed

Loads once and throws me away #13129

quimico99 opened this issue Oct 18, 2018 · 2 comments
Labels
Android Mapbox Maps SDK for Android needs information

Comments

@quimico99
Copy link

quimico99 commented Oct 18, 2018

Hello, I hope you can understand I speak Spanish and I had to help myself with a translator. It turns out that I want to load a mapFragment by means of a button, which is good for me the first time, it is loaded, but when I fly to hit the button with the map already loaded or it bounces me and or it paralyzes the sight that no longer lets me move in the map. I leave the code to have if they help me. The same happens to me when I want to work with a navigationdrawer.

Configuration

Android versions: 5.0
Device models:MEMU, HTC M7
Mapbox SDK versions:6.5.0

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.maps.SupportMapFragment;

public class MainActivity extends AppCompatActivity {

Bundle checkea;

FragmentTransaction transaction;
SupportMapFragment mapFragment;
MapboxMapOptions options;




@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        Mapbox.getInstance(this, getString(R.string.mapbox_access_token));


    checkea = savedInstanceState;
    Button boton = (Button) findViewById(R.id.irmap);

// Create supportMapFragment

    boton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            if (savedInstanceState == null) {

                // Create fragment
                final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

                LatLng patagonia = new LatLng(-52.6885, -70.1395);

                // Build mapboxMap
                MapboxMapOptions options = new MapboxMapOptions();
                options.styleUrl(Style.SATELLITE);
                options.camera(new CameraPosition.Builder()
                        .target(patagonia)
                        .zoom(9)
                        .build());

                // Create map fragment
                mapFragment = SupportMapFragment.newInstance(options);

                // Add map fragment to parent container
                transaction.add(R.id.fragment_contenedor, mapFragment, "com.mapbox.map");
                transaction.commit();
            } else {
                mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentByTag("com.mapbox.map");
            }

            mapFragment.getMapAsync(new OnMapReadyCallback() {
                @Override
                public void onMapReady(MapboxMap mapboxMap) {

                    // Customize map with markers, polylines, etc.

                }
            });


        }
    });



}

}

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Bundle.getBoolean(java.lang.String, boolean)' on a null object reference
    at com.mapbox.mapboxsdk.storage.FileSource.getCachePath(FileSource.java:88)
    at com.mapbox.mapboxsdk.storage.FileSource$FileDirsPathsTask.doInBackground(FileSource.java:165)
    at com.mapbox.mapboxsdk.storage.FileSource$FileDirsPathsTask.doInBackground(FileSource.java:155)
    at android.os.AsyncTask$2.call(AsyncTask.java)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)
@tobrun tobrun added the Android Mapbox Maps SDK for Android label Oct 19, 2018
@tobrun
Copy link
Member

tobrun commented Oct 19, 2018

@quimico99 I copied over your code and not able to reproduce your issue.
The exception shown is expected and we removed logging of it in #13102. Would you be able to try reproducing this issue with v6.6.1?

@quimico99
Copy link
Author

I was able to solve my problem. And it is that I structure my code badly. Another problem that I corrected is that the fragmentTransaction put it out of the onclicklistener and I skip another error by repetition of the commit. This is corrected by entering it into the ONCLICKlistener.

public class MainActivity extends AppCompatActivity {
Bundle checkea;

FragmentTransaction transaction;
SupportMapFragment mapFragment;
MapboxMapOptions options;


@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Mapbox.getInstance(getApplicationContext(), getString(R.string.mapbox_access_token));
    setContentView(R.layout.activity_main);


    checkea = savedInstanceState;
    Button boton = (Button) findViewById(R.id.irmap);

    options = new MapboxMapOptions();
    LatLng patagonia = new LatLng(-52.6885, -70.1395);

    // Build mapboxMap

    options.styleUrl(Style.SATELLITE);
    options.camera(new CameraPosition.Builder()
            .target(patagonia)
            .zoom(9)
            .build());

    // Create supportMapFragment


    mapFragment = SupportMapFragment.newInstance(options);


    boton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            transaction = getSupportFragmentManager().beginTransaction();
    if(!mapFragment.isAdded()) {
        transaction.replace(R.id.fragment_contenedor, mapFragment);

    }else{
        //transaction.remove(mapFragment);
        //transaction.replace(R.id.fragment_contenedor, mapFragment);
        transaction.detach(mapFragment).attach(mapFragment);
    }
            transaction.addToBackStack(null);
            transaction.commit();

        }

    });



}

}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android needs information
Projects
None yet
Development

No branches or pull requests

2 participants