IllegalStateException: Could not execute method of the activity with Android -
when press button(named "current location") should shows current address on textview(named "tvaddress") , should place marker on map in meantime.but it's not working expect. it's giving me errors.errors given below.
error :
02-05 23:37:22.429: e/androidruntime(20293): fatal exception: main 02-05 23:37:22.429: e/androidruntime(20293): java.lang.illegalstateexception: not execute method of activity 02-05 23:37:22.429: e/androidruntime(20293): @ android.view.view$1.onclick(view.java:3680) 02-05 23:37:22.429: e/androidruntime(20293): @ android.view.view.performclick(view.java:4191) 02-05 23:37:22.429: e/androidruntime(20293): @ android.view.view$performclick.run(view.java:17229) 02-05 23:37:22.429: e/androidruntime(20293): @ android.os.handler.handlecallback(handler.java:615) 02-05 23:37:22.429: e/androidruntime(20293): @ android.os.handler.dispatchmessage(handler.java:92) 02-05 23:37:22.429: e/androidruntime(20293): @ android.os.looper.loop(looper.java:137) 02-05 23:37:22.429: e/androidruntime(20293): @ android.app.activitythread.main(activitythread.java:4960) 02-05 23:37:22.429: e/androidruntime(20293): @ java.lang.reflect.method.invokenative(native method) 02-05 23:37:22.429: e/androidruntime(20293): @ java.lang.reflect.method.invoke(method.java:511) 02-05 23:37:22.429: e/androidruntime(20293): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1038) 02-05 23:37:22.429: e/androidruntime(20293): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:805) 02-05 23:37:22.429: e/androidruntime(20293): @ dalvik.system.nativestart.main(native method) 02-05 23:37:22.429: e/androidruntime(20293): caused by: java.lang.reflect.invocationtargetexception 02-05 23:37:22.429: e/androidruntime(20293): @ java.lang.reflect.method.invokenative(native method) 02-05 23:37:22.429: e/androidruntime(20293): @ java.lang.reflect.method.invoke(method.java:511) 02-05 23:37:22.429: e/androidruntime(20293): @ android.view.view$1.onclick(view.java:3675) 02-05 23:37:22.429: e/androidruntime(20293): ... 11 more 02-05 23:37:22.429: e/androidruntime(20293): caused by: java.lang.nullpointerexception 02-05 23:37:22.429: e/androidruntime(20293): @ com.mamun.tasktest.mapactivity.marker(mapactivity.java:129) 02-05 23:37:22.429: e/androidruntime(20293): ... 14 more
mapactivity.java
package com.mamun.tasktest; import java.io.ioexception; import java.util.arraylist; import android.app.activity; import android.app.alertdialog; import android.content.dialoginterface; import android.content.intent; import android.location.address; import android.location.geocoder; import android.location.location; import android.location.locationmanager; import android.os.bundle; import android.provider.settings; import android.view.view; import android.widget.button; import android.widget.textview; import android.widget.toast; import com.google.android.gms.common.connectionresult; import com.google.android.gms.common.googleplayservicesclient; import com.google.android.gms.location.locationclient; import com.google.android.gms.location.locationlistener; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.googlemap.onmarkerdraglistener; import com.google.android.gms.maps.model.bitmapdescriptorfactory; 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 mapactivity extends activity implements googleplayservicesclient.connectioncallbacks, googleplayservicesclient.onconnectionfailedlistener, locationlistener { private locationmanager manager; private textview tvaddress; private button btncurrent; private locationclient locationclient; private googlemap googlemap; private mapfragment mapfragment; @override protected void oncreate(bundle savedinstancestate) { manager = (locationmanager) getsystemservice(location_service); tvaddress = (textview) findviewbyid(r.id.tvaddress); btncurrent= (button)findviewbyid(r.id.btncurrent); super.oncreate(savedinstancestate); if (manager.isproviderenabled(locationmanager.gps_provider)) { setcontentview(r.layout.map); } else if (!manager.isproviderenabled(locationmanager.gps_provider)) { alertdialog.builder builder = new alertdialog.builder(this); builder.settitle("gps disabled"); builder.setmessage("please enable gps use application.\nwould enable gps?"); builder.setpositivebutton("yes", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { intent = new intent( settings.action_location_source_settings); startactivity(i); setcontentview(r.layout.map); mapfragment = (mapfragment) getfragmentmanager().findfragmentbyid( r.id.maps); googlemap = mapfragment.getmap(); } }); builder.setnegativebutton("no", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { finish(); } }); builder.create().show(); } locationclient = new locationclient(this, this, this); } public void marker(view v) { // add marker location currentlocation = locationclient.getlastlocation(); double lat = currentlocation.getlatitude(); double lng = currentlocation.getlongitude(); markeroptions options = new markeroptions() .position(new latlng(lat, lng)) .title("i here") .snippet("this current location") .icon(bitmapdescriptorfactory .defaultmarker(bitmapdescriptorfactory.hue_azure)); if (googlemap != null) { googlemap.addmarker(options); } else { toast.maketext(getapplicationcontext(), "map null", toast.length_long).show(); } geocoder geocoder = new geocoder(this); try { arraylist<address> addresses = (arraylist<address>) geocoder .getfromlocation(currentlocation.getlatitude(), currentlocation.getlongitude(), 5); address addr = addresses.get(0); tvaddress.settext(addr.getaddressline(0) + "-" + addr.getadminarea() + "-" + addr.getcountryname()); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } @override protected void onresume() { // todo auto-generated method stub super.onresume(); locationclient.connect(); } @override protected void onpause() { // todo auto-generated method stub super.onpause(); locationclient.disconnect(); } @override public void onlocationchanged(location location) { // todo auto-generated method stub } @override public void onconnectionfailed(connectionresult result) { // todo auto-generated method stub } @override public void onconnected(bundle connectionhint) { } @override public void ondisconnected() { // todo auto-generated method stub } }
map.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <edittext android:id="@+id/etsearch" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="search location" > <requestfocus /> </edittext> <textview android:id="@+id/tvaddress" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <button android:id="@+id/btncurrent" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="marker" android:text="current location" android:layout_marginleft="98dp" /> <button android:id="@+id/btnsave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="save" /> </linearlayout> </linearlayout> <framelayout android:id="@+id/map_container" android:layout_width="match_parent" android:layout_height="match_parent" > <fragment android:id="@+id/maps" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.mapfragment" /> </framelayout> </linearlayout>
Comments
Post a Comment