java - Android Studio, Google Maps Search Button is not working -
i worte android application google maps integration. found tutorial in youtube , did in way in video search location button click. have simple plaintext , button search. button set onclick method onsearch() can find code bellow.
when press on button, app crashing. wrong in code??
thank in advance:
public void onsearch(view v){ //textfield in google maps activity edittext location_tf=(edittext) findviewbyid(r.id.tfadress); //put written input string work string location = location_tf.gettext().tostring(); //list geocoder list<address> addresslist= null; if(location!= null || !location.equals("")){ geocoder geocoder = new geocoder(this); try { addresslist=geocoder.getfromlocationname(location,1); } catch (ioexception e) { e.printstacktrace(); } address address = addresslist.get(0); latlng latlng= new latlng(address.getlatitude(), address.getlongitude()); mmap.addmarker(new markeroptions().position(latlng).title("searched location")); //movethecamera searched location 18 zoom mmap.movecamera(cameraupdatefactory.newlatlngzoom(latlng, 18)); } }
error log:
08-18 13:25:36.182 2619-2619/com.group6.travlhoe e/androidruntime: fatal exception: main process: com.group6.travlhoe, pid: 2619 java.lang.illegalstateexception: not execute method android:onclick @ android.view.view$declaredonclicklistener.onclick(view.java:5336) @ android.view.view.performclick(view.java:6256) @ android.view.view$performclick.run(view.java:24697) @ android.os.handler.handlecallback(handler.java:789) @ android.os.handler.dispatchmessage(handler.java:98) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767) caused by: java.lang.reflect.invocationtargetexception @ java.lang.reflect.method.invoke(native method) @ android.view.view$declaredonclicklistener.onclick(view.java:5331) @ android.view.view.performclick(view.java:6256) @ android.view.view$performclick.run(view.java:24697) @ android.os.handler.handlecallback(handler.java:789) @ android.os.handler.dispatchmessage(handler.java:98) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767) caused by: java.lang.nullpointerexception: attempt invoke interface method 'java.lang.object java.util.list.get(int)' on null object reference @ com.group6.takeoff.mapsactivity.onmapsearch(mapsactivity.java:84) @ java.lang.reflect.method.invoke(native method) @ android.view.view$declaredonclicklistener.onclick(view.java:5331) @ android.view.view.performclick(view.java:6256) @ android.view.view$performclick.run(view.java:24697) @ android.os.handler.handlecallback(handler.java:789) @ android.os.handler.dispatchmessage(handler.java:98) @ android.os.looper.loop(looper.java:164) @ android.app.activitythread.main(activitythread.java:6541) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygote$methodandargscaller.run(zygote.java:240) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:767)
Comments
Post a Comment