android - Crashes when showing map on real device, running on emulator shows google play service missing -
when ever run app on emulator shows google play service missing.but when run same application on real device unexpectedly stops application making crash here code map
`
<uses-sdk android:minsdkversion="8" android:targetsdkversion="8" /> <uses-permission android:name="android.permission.read_contacts" /> <application android:allowbackup="true" android:icon="@drawable/loc_finder" android:label="@string/app_name" android:theme="@style/apptheme" > <uses-library android:name="com.google.android.maps" /> <service android:name="jade.android.microruntimeservice" /> <activity android:name="com.example.location_finder.login_activity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name="in.wptrafficanalyzer.proximitymapv2.mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".proximityactivity" android:label="@string/app_name" > <intent-filter > <action android:name="in.wptrafficanalyzer.activity.proximity"/> <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name=".notificationview" android:label="@string/app_name" > <intent-filter > <category android:name="android.intent.category.default" /> </intent-filter> </activity> <activity android:name="com.example.location_finder.new_user_activity" > </activity> <activity android:name="com.example.location_finder.welcome_activity" > </activity> <activity android:name="com.example.location_finder.search_friend_activity" > </activity> <activity android:name="com.example.location_finder.search_location_activity" > </activity> <activity android:name="com.example.location_finder.gpslocatoractivity" > </activity> <activity android:name="chat.client.gui.mainactivity" /> <activity android:name="chat.client.gui.chatactivity" /> <activity android:name="chat.client.gui.chatclientactivity" /> <activity android:name="chat.client.gui.participantsactivity" /> </application> <uses-permission android:name="in.wptrafficanalyzer.proximitymapv2.permission.maps_receive" android:protectionlevel="signature"/> <uses-permission android:name="in.wptrafficanalyzer.proximitymapv2.permission.maps_receive"/> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <uses-permission android:name="android.permission.access_coarse_location"/> <uses-permission android:name="android.permission.access_fine_location"/> <uses-feature android:glesversion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.internet" > </uses-permission> <uses-permission android:name="android.permission.access_network_state" > </uses-permission> <uses-permission android:name="android.permission.access_coarse_location" > </uses-permission> <uses-permission android:name="android.permission.access_fine_location" > </uses-permission> <uses-permission android:name="android.permission.access_mock_location" /> <uses-permission android:name="android.permission.vibrate" /> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasydgah79jaiabl54k8v8hfb7uzopkvwtgzw"/> </manifest>
`
mainactivity.java
public class mainactivity extends fragmentactivity
{
googlemap googlemap; locationmanager locationmanager; pendingintent pendingintent; sharedpreferences sharedpreferences; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // getting google play availability status int status = googleplayservicesutil.isgoogleplayservicesavailable(getbasecontext()); // showing status if(status!=connectionresult.success){ // google play services not available int requestcode = 10; dialog dialog = googleplayservicesutil.geterrordialog(status, this, requestcode); dialog.show(); }else { // google play services available // getting reference supportmapfragment of activity_main.xml supportmapfragment fm = (supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map); // getting googlemap object fragment googlemap = fm.getmap(); // enabling mylocation layer of google map googlemap.setmylocationenabled(true); // getting locationmanager object system service location_service locationmanager = (locationmanager) getsystemservice(location_service); // opening sharedpreferences object sharedpreferences = getsharedpreferences("location", 0); // getting stored latitude if exists else return 0 string lat = sharedpreferences.getstring("lat", "0"); // getting stored longitude if exists else return 0 string lng = sharedpreferences.getstring("lng", "0"); // getting stored zoom level if exists else return 0 string zoom = sharedpreferences.getstring("zoom", "0"); // if coordinates stored earlier if(!lat.equals("0")){ // drawing circle on map drawcircle(new latlng(double.parsedouble(lat), double.parsedouble(lng))); // drawing marker on map drawmarker(new latlng(double.parsedouble(lat), double.parsedouble(lng))); // moving cameraposition clicked position googlemap.movecamera(cameraupdatefactory.newlatlng(new latlng(double.parsedouble(lat), double.parsedouble(lng)))); // setting zoom level in map googlemap.animatecamera(cameraupdatefactory.zoomto(float.parsefloat(zoom))); } googlemap.setonmapclicklistener(new onmapclicklistener() { //@override public void onmapclick(latlng point) { // removes existing marker google map googlemap.clear(); // drawing marker on map drawmarker(point); // drawing circle on map drawcircle(point); // intent call activity proximityactivity intent proximityintent = new intent("in.wptrafficanalyzer.activity.proximity"); // creating pending intent invoked locationmanager when specified region // entered or exited pendingintent = pendingintent.getactivity(getbasecontext(), 0, proximityintent,intent.flag_activity_new_task); // setting proximity alert // pending intent invoked when device enters or exits region 20 meters // away marked point // -1 indicates that, monitor not expired locationmanager.addproximityalert(point.latitude, point.longitude, 20, -1, pendingintent); /** opening editor object write data sharedpreferences */ sharedpreferences.editor editor = sharedpreferences.edit(); /** storing latitude of current location shared preferences */ editor.putstring("lat", double.tostring(point.latitude)); /** storing longitude of current location shared preferences */ editor.putstring("lng", double.tostring(point.longitude)); /** storing zoom level shared preferences */ editor.putstring("zoom", float.tostring(googlemap.getcameraposition().zoom)); /** saving values stored in shared preferences */ editor.commit(); toast.maketext(getbasecontext(), "proximity alert added", toast.length_short).show(); } }); googlemap.setonmaplongclicklistener(new onmaplongclicklistener() { //@override public void onmaplongclick(latlng point) { intent proximityintent = new intent("in.wptrafficanalyzer.activity.proximity"); pendingintent = pendingintent.getactivity(getbasecontext(), 0, proximityintent,intent.flag_activity_new_task); // removing proximity alert locationmanager.removeproximityalert(pendingintent); // removing marker , circle google map googlemap.clear(); // opening editor object delete data sharedpreferences sharedpreferences.editor editor = sharedpreferences.edit(); // clearing editor editor.clear(); // committing changes editor.commit(); toast.maketext(getbasecontext(), "proximity alert removed", toast.length_long).show(); } }); } } private void drawmarker(latlng point){ // creating instance of markeroptions markeroptions markeroptions = new markeroptions(); // setting latitude , longitude marker markeroptions.position(point); // adding marker on google map googlemap.addmarker(markeroptions); } private void drawcircle(latlng point){ // instantiating circleoptions draw circle around marker circleoptions circleoptions = new circleoptions(); // specifying center of circle circleoptions.center(point); // radius of circle circleoptions.radius(20); // border color of circle circleoptions.strokecolor(color.black); // fill color of circle circleoptions.fillcolor(0x30ff0000); // border width of circle circleoptions.strokewidth(2); // adding circle googlemap googlemap.addcircle(circleoptions); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; }
}
logcat
05-04 22:36:22.820: d/sensormanager(29794): registerlistener :: handle = 0 name= lsm330dlc 3-axis accelerometer delay= 200000 listener= android.view.orientationeventlistener$sensoreventlistenerimpl@42c2ce28 05-04 22:36:22.870: d/dalvikvm(29794): gc_concurrent freed 209k, 9% free 13173k/14407k, paused 5ms+1ms, total 17ms 05-04 22:36:22.875: d/androidruntime(29794): shutting down vm 05-04 22:36:22.875: w/dalvikvm(29794): threadid=1: thread exiting uncaught exception (group=0x41e542a0) 05-04 22:36:22.885: e/androidruntime(29794): fatal exception: main 05-04 22:36:22.885: e/androidruntime(29794): java.lang.runtimeexception: unable start activity componentinfo{com.example.location_finder/in.wptrafficanalyzer.proximitymapv2.mainactivity}: java.lang.nullpointerexception 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activitythread.performlaunchactivity(activitythread.java:2100) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2125) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activitythread.access$600(activitythread.java:140) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activitythread$h.handlemessage(activitythread.java:1227) 05-04 22:36:22.885: e/androidruntime(29794): @ android.os.handler.dispatchmessage(handler.java:99) 05-04 22:36:22.885: e/androidruntime(29794): @ android.os.looper.loop(looper.java:137) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activitythread.main(activitythread.java:4898) 05-04 22:36:22.885: e/androidruntime(29794): @ java.lang.reflect.method.invokenative(native method) 05-04 22:36:22.885: e/androidruntime(29794): @ java.lang.reflect.method.invoke(method.java:511) 05-04 22:36:22.885: e/androidruntime(29794): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1006) 05-04 22:36:22.885: e/androidruntime(29794): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:773) 05-04 22:36:22.885: e/androidruntime(29794): @ dalvik.system.nativestart.main(native method) 05-04 22:36:22.885: e/androidruntime(29794): caused by: java.lang.nullpointerexception 05-04 22:36:22.885: e/androidruntime(29794): @ in.wptrafficanalyzer.proximitymapv2.mainactivity.oncreate(mainactivity.java:55) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activity.performcreate(activity.java:5206) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1083) 05-04 22:36:22.885: e/androidruntime(29794): @ android.app.activitythread.performlaunchactivity(activitythread.java:2064) 05-04 22:36:22.885: e/androidruntime(29794): ... 11 more
maybe had fixed issue.
but code side, need check whether fm null before tried use it.
supportmapfragment fm = (supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.map);
Comments
Post a Comment