Bonjour,
J'ai une classe qui renvoie la longitude et la latitude du téléphone (ou de sa connexion sur le réseau) dans le terminal.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
     protected void onCreate(Bundle savedInstanceState) {
        ...
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        if (locationManager != null)
            mListener = new LocationListener()
            {
                public void onLocationChanged(Location location) {displayPosition();}
                public void onProviderDisabled(String provider) {}
                public void onProviderEnabled(String provider) {}
                public void onStatusChanged(String provider,int status, Bundle extras) {}
            };
    }
 
 
    @Override
    public void onResume() {
        super.onResume();
        if (locationManager != null) {
            displayPosition();
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            locationManager.requestLocationUpdates(locationProvider, 6000, 100, mListener);
        }
    }
 
    @Override
    public void onPause() {
        if (locationManager != null)
        {
            if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
 
            locationManager.removeUpdates(mListener);
        }
        super.onPause();
    }
 
    public void displayPosition() {
        String msg = null;
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            // TODO: Consider calling
            //    ActivityCompat#requestPermissions
            // here to request the missing permissions, and then overriding
            //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
            //                                          int[] grantResults)
            // to handle the case where the user grants the permission. See the documentation
            // for ActivityCompat#requestPermissions for more details.
            return;
        }
        Location location = locationManager.getLastKnownLocation(locationProvider);
        if (location != null)
            msg = String.format("(%.2f, %.2f)",location.getLatitude(), location.getLongitude());
        else
            msg = "position inconnue";
        Log.v("Position", msg);
    }
et j'obtiens cet erreur

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
09-27 15:17:42.099 8025-8025/com.example.user.geolocalisaton E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.example.i.geolocalisaton, PID: 8025
                                                                            android.util.SuperNotCalledException: Activity {com.example.i.geolocalisaton/com.example.user.geolocalisaton.MainActivity} did not call through to super.onPause()
                                                                                at android.app.Activity.performPause(Activity.java:6352)
                                                                                at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1311)
                                                                                at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3367)
                                                                                at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3340)
                                                                                at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3315)
                                                                                at android.app.ActivityThread.-wrap13(ActivityThread.java)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                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)