Почему у меня "вылетает" приложение, когда я пытаюсь получить координаты с GPS. Если что в коде я пометил комментарием где ошибка вылетает, во время запуска.
public abstract class MainActivity extends FragmentActivity implements OnMapReadyCallback, LocationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync((OnMapReadyCallback) this);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);// Вот тут приложение вылетает !!!
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
public class coordinats{
public double Latitude;
public double Longitude;
}
public void onLocationChanged(Location location)
{
if (location != null)
{
coordinats position = new coordinats();
position.Latitude = location.getLatitude();
position.Longitude = location.getLongitude();
new Gson().toJson(position);
}
}
public void conect (View v){
Thread network = new Thread(new ClientThread());
network.start();
}
private Socket socket;
private static final int SERVERPORT = 1111;
private static final String SERVER_IP = "1.23.45.67";
class ClientThread implements Runnable {
@Override
public void run() {
try {
InetAddress serverAddr = InetAddress.getByName(SERVER_IP);
socket = new Socket(serverAddr, SERVERPORT);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
public void onMapReady(GoogleMap map) {
// Add a marker in Sydney, Australia, and move the camera.
LatLng sydney = new LatLng(-34, 151);
map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
map.moveCamera(CameraUpdateFactory.newLatLng(sydney));
final LatLng MELBOURNE = new LatLng(-37.813, 144.962);
Marker melbourne = map.addMarker(new MarkerOptions()
.position(MELBOURNE)
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.fingerbig)));
--- UPD ---
05-10 16:28:54.579 3967-3974/myhome.gps_tracker I/art: Debugger is active
05-10 16:28:54.590 3967-3967/myhome.gps_tracker I/System.out: Debugger has connected
05-10 16:28:54.590 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:54.800 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:55.010 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:55.220 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:55.429 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:55.640 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:55.849 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:56.059 3967-3967/myhome.gps_tracker I/System.out: waiting for debugger to settle...
05-10 16:28:56.269 3967-3967/myhome.gps_tracker I/System.out: debugger has settled (1431)
05-10 16:28:56.283 3967-3967/myhome.gps_tracker W/System: ClassLoader referenced unknown path: /data/app/myhome.gps_tracker-1/lib/x86
05-10 16:28:56.379 3967-3967/myhome.gps_tracker W/System: ClassLoader referenced unknown path: /data/app/myhome.gps_tracker-1/lib/x86
05-10 16:28:56.536 3967-4022/myhome.gps_tracker I/GMPM: App measurement is starting up
05-10 16:28:56.547 3967-4022/myhome.gps_tracker E/GMPM: getGoogleAppId failed with status: 10
05-10 16:28:56.547 3967-4022/myhome.gps_tracker E/GMPM: Uploading is not possible. App measurement disabled
05-10 16:28:56.551 3967-3967/myhome.gps_tracker D/AndroidRuntime: Shutting down VM
05-10 16:28:56.551 3967-3967/myhome.gps_tracker E/AndroidRuntime: FATAL EXCEPTION: main
Process: myhome.gps_tracker, PID: 3967
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{myhome.gps_tracker/myhome.gps_tracker.MainActivity}: java.lang.InstantiationException: java.lang.Class<myhome.gps_tracker.MainActivity> cannot be instantiated
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
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)
Caused by: java.lang.InstantiationException: java.lang.Class<myhome.gps_tracker.MainActivity> cannot be instantiated
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
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)
ACCESS_FINE_LOCATION
добавили в манифест?