android - Google Map api v2 - setUpMap() causes errors -
what wrong code? doing map/location app. showing map ok trying add setupmap() method/function causes app stop.
main_layout.xml:
<?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.mapfragment"/>
activity:
package tri.mylocapp;
//import... public class mainactivity extends activity implements locationlistener{ googlemap googlemap = null; latlng latlng; locationmanager lm; string provider; location location; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); if (isgoogleplay()){ setcontentview(r.layout.activity_main); setupmap(); } } private boolean isgoogleplay(){ int status = googleplayservicesutil.isgoogleplayservicesavailable(this); if (status == connectionresult.success){ log.d("mytag", "google ok"); return true; } else{ log.d("mytag","google not ok"); toast.maketext(this, "googleplay not available", toast.length_short).show(); } return false; } private void setupmap(){ if (googlemap == null){ log.d("mytag", "googlemap null, making available"); googlemap = ((mapfragment)getfragmentmanager().findfragmentbyid(r.id.map)).getmap(); if (googlemap != null){ log.d("mytag", "googlemap not null"); googlemap.setmylocationenabled(true); provider = lm.getbestprovider(new criteria(), true); if (provider == null){ onproviderdisabled(provider); } location = lm.getlastknownlocation(provider); if (location != null){ onlocationchanged(location); } } } } @override public void onlocationchanged(location location) { latlng = new latlng(location.getlatitude(), location.getlongitude()); googlemap.movecamera(cameraupdatefactory.newlatlng(latlng)); googlemap.animatecamera(cameraupdatefactory.zoomto(10)); } @override public void onstatuschanged(string provider, int status, bundle extras) { // todo auto-generated method stub } @override public void onproviderenabled(string provider) { // todo auto-generated method stub } @override public void onproviderdisabled(string provider) { // todo auto-generated method stub } }
logcat (errors , mytag):
04-06 12:54:13.099: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:54:13.099: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:54:13.103: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:54:13.103: e/socketstream(342): readfully waiting 255984 bytes, got 4 04-06 12:54:13.103: e/socketstream(342): readfully waiting 255980 bytes, got 49152 04-06 12:54:13.103: e/socketstream(342): readfully waiting 206828 bytes, got 49152 04-06 12:54:13.103: e/socketstream(342): readfully waiting 157676 bytes, got 49152 04-06 12:54:13.103: e/socketstream(342): readfully waiting 108524 bytes, got 16384 04-06 12:54:13.255: e/trace(1750): error opening trace file: no such file or directory (2) 04-06 12:54:20.723: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:54:20.723: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:54:20.723: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:54:20.723: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 12:54:37.215: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:54:37.215: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:54:37.215: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:54:37.215: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 12:54:39.579: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:54:39.579: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:54:39.579: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:54:39.579: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 12:54:39.599: e/trace(1769): error opening trace file: no such file or directory (2) 04-06 12:54:39.607: e/jdwp(1769): failed sending reply debugger: broken pipe 04-06 12:54:41.403: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:54:41.403: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:54:41.403: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:54:41.403: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 12:54:41.679: e/binarydictionarygetter(531): not find dictionary pack 04-06 12:54:41.679: e/activitythread(531): failed find provider info com.android.inputmethod.latin.dictionarypack 04-06 12:54:41.711: e/dalvikvm(1633): not find class 'android.app.appopsmanager', referenced method box.a 04-06 12:54:43.767: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:54:43.767: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:54:43.767: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:54:43.767: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 12:55:57.495: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:55:57.495: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:55:57.499: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:55:57.499: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 12:55:57.531: e/trace(1841): error opening trace file: no such file or directory (2) 04-06 12:55:57.827: e/androidruntime(1841): fatal exception: main 04-06 12:55:57.827: e/androidruntime(1841): java.lang.runtimeexception: unable start activity componentinfo{tri.mylocapp/tri.mylocapp.mainactivity}: java.lang.nullpointerexception 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activitythread.access$600(activitythread.java:130) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 04-06 12:55:57.827: e/androidruntime(1841): @ android.os.handler.dispatchmessage(handler.java:99) 04-06 12:55:57.827: e/androidruntime(1841): @ android.os.looper.loop(looper.java:137) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activitythread.main(activitythread.java:4745) 04-06 12:55:57.827: e/androidruntime(1841): @ java.lang.reflect.method.invokenative(native method) 04-06 12:55:57.827: e/androidruntime(1841): @ java.lang.reflect.method.invoke(method.java:511) 04-06 12:55:57.827: e/androidruntime(1841): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 04-06 12:55:57.827: e/androidruntime(1841): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 04-06 12:55:57.827: e/androidruntime(1841): @ dalvik.system.nativestart.main(native method) 04-06 12:55:57.827: e/androidruntime(1841): caused by: java.lang.nullpointerexception 04-06 12:55:57.827: e/androidruntime(1841): @ tri.mylocapp.mainactivity.setupmap(mainactivity.java:61) 04-06 12:55:57.827: e/androidruntime(1841): @ tri.mylocapp.mainactivity.oncreate(mainactivity.java:35) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activity.performcreate(activity.java:5008) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 04-06 12:55:57.827: e/androidruntime(1841): @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 04-06 12:55:57.827: e/androidruntime(1841): ... 11 more 04-06 12:55:57.859: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 12:55:57.859: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 12:55:57.859: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 12:55:57.859: e/socketstream(342): readfully waiting 255984 bytes, got 49152 04-06 12:55:57.859: e/socketstream(342): readfully waiting 206832 bytes, got 49152 04-06 13:13:01.315: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 13:13:01.315: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 13:13:01.315: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 13:13:01.315: e/socketstream(342): readfully waiting 255984 bytes, got 16384 04-06 13:13:01.363: e/trace(1874): error opening trace file: no such file or directory (2) 04-06 13:13:01.375: e/jdwp(1874): failed sending reply debugger: broken pipe 04-06 13:13:01.643: e/androidruntime(1874): fatal exception: main 04-06 13:13:01.643: e/androidruntime(1874): java.lang.runtimeexception: unable start activity componentinfo{tri.mylocapp/tri.mylocapp.mainactivity}: java.lang.nullpointerexception 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activitythread.performlaunchactivity(activitythread.java:2059) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2084) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activitythread.access$600(activitythread.java:130) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activitythread$h.handlemessage(activitythread.java:1195) 04-06 13:13:01.643: e/androidruntime(1874): @ android.os.handler.dispatchmessage(handler.java:99) 04-06 13:13:01.643: e/androidruntime(1874): @ android.os.looper.loop(looper.java:137) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activitythread.main(activitythread.java:4745) 04-06 13:13:01.643: e/androidruntime(1874): @ java.lang.reflect.method.invokenative(native method) 04-06 13:13:01.643: e/androidruntime(1874): @ java.lang.reflect.method.invoke(method.java:511) 04-06 13:13:01.643: e/androidruntime(1874): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 04-06 13:13:01.643: e/androidruntime(1874): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 04-06 13:13:01.643: e/androidruntime(1874): @ dalvik.system.nativestart.main(native method) 04-06 13:13:01.643: e/androidruntime(1874): caused by: java.lang.nullpointerexception 04-06 13:13:01.643: e/androidruntime(1874): @ tri.mylocapp.mainactivity.setupmap(mainactivity.java:61) 04-06 13:13:01.643: e/androidruntime(1874): @ tri.mylocapp.mainactivity.oncreate(mainactivity.java:35) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activity.performcreate(activity.java:5008) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 04-06 13:13:01.643: e/androidruntime(1874): @ android.app.activitythread.performlaunchactivity(activitythread.java:2023) 04-06 13:13:01.643: e/androidruntime(1874): ... 11 more 04-06 13:13:01.671: e/socketstream(342): readfully waiting 403440 bytes, got 49152 04-06 13:13:01.671: e/socketstream(342): readfully waiting 354288 bytes, got 49152 04-06 13:13:01.671: e/socketstream(342): readfully waiting 305136 bytes, got 49152 04-06 13:13:01.671: e/socketstream(342): readfully waiting 255984 bytes, got 49152 04-06 13:13:01.671: e/socketstream(342): readfully waiting 206832 bytes, got 49152
you need initialize googlemap object null before try compare value anything.
ie.
private void setupmap(){ if (googlemap == null){ //in code googlemap var uninitialized @ point ...}}
try changing line:
googlemap googlemap;
to
googlemap googlemap = null;
oh, , way; wanted including debug information. i've been browsing around of these android questions on here, , keep seeing situations people include code; not error information. in mind realistically equivalent going mechanic shop , asking mechanic why car driving funny, , when ask go outside , see it; tell them in garage @ home....
Comments
Post a Comment