Google Maps Android V2 application crashing-Collection of common programming errors
StudentI am working on a project that includes location detection using the GPS so I found this code that included a working .apk file but when I tried to compile it and run it, it always crashes. The application crashes when I try opening it in an emulator or on a Samsung S4 mobile. N.B. I’ve chosen the correct target which is API 17 and downloaded Google play services and included it in the library of the project.
Here is the code if anyone can help
Manifest file
MainActivity.java
package info.tekguc.umut.googlemapsmapsandroidv2; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.MapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.Marker; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends Activity { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap(); mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE); final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097); Marker ciu = mMap.addMarker(new MarkerOptions().position(CIU).title( "My Office")); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
activity_main.xml
Logcat
12-25 17:30:32.450: D/dalvikvm(286): GC_FOR_ALLOC freed 6K, 15% free 7250K/8524K, paused 487ms, total 487ms 12-25 17:30:32.940: D/dalvikvm(286): GC_FOR_ALLOC freed 253K, 18% free 6999K/8524K, paused 463ms, total 465ms 12-25 17:30:32.950: W/BroadcastQueue(286): Failure sending broadcast Intent { act=android.intent.action.SIM_STATE_CHANGED flg=0x20000010 (has extras) } 12-25 17:30:32.950: W/BroadcastQueue(286): android.os.DeadObjectException 12-25 17:30:32.950: W/BroadcastQueue(286): at android.os.BinderProxy.transact(Native Method) 12-25 17:30:32.950: W/BroadcastQueue(286): at android.content.IIntentReceiver$Stub$Proxy.performReceive(IIntentReceiver.java:124) 12-25 17:30:32.950: W/BroadcastQueue(286): at com.android.server.am.BroadcastQueue.performReceiveLocked(BroadcastQueue.java:376) 12-25 17:30:32.950: W/BroadcastQueue(286): at com.android.server.am.BroadcastQueue.deliverToRegisteredReceiverLocked(BroadcastQueue.java:439) 12-25 17:30:32.950: W/BroadcastQueue(286): at com.android.server.am.BroadcastQueue.processNextBroadcast(BroadcastQueue.java:487) 12-25 17:30:32.950: W/BroadcastQueue(286): at com.android.server.am.BroadcastQueue$1.handleMessage(BroadcastQueue.java:140) 12-25 17:30:32.950: W/BroadcastQueue(286): at android.os.Handler.dispatchMessage(Handler.java:99) 12-25 17:30:32.950: W/BroadcastQueue(286): at android.os.Looper.loop(Looper.java:137) 12-25 17:30:32.950: W/BroadcastQueue(286): at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1480) 12-25 17:30:34.300: I/ActivityManager(286): Start proc com.google.process.gapps for content provider com.google.android.gsf/.settings.GoogleSettingsProvider: pid=518 uid=10019 gids={50019, 3003, 1007, 1028, 1015, 1006, 2001, 3006} 12-25 17:30:34.350: W/ActivityManager(286): Activity idle timeout for ActivityRecord{40f692c8 u0 com.android.launcher/com.android.launcher2.Launcher} 12-25 17:30:34.380: D/dalvikvm(37): GC_EXPLICIT freed 35K, 6% free 2403K/2552K, paused 4ms+7ms, total 96ms 12-25 17:30:34.410: W/ActivityManager(286): Timeout executing service: ServiceRecord{40fa9d20 u0 com.android.inputmethod.latin/.LatinIME} 12-25 17:30:34.480: D/dalvikvm(37): GC_EXPLICIT freed