i don't seem know how go it. once click floating button app crashes haven't declared secondactivity.java in manifest
here activity_maps.xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mapsactivity"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mapsactivity" tools:layout="@android:layout/simple_spinner_dropdown_item" /> <imagebutton android:layout_width="65dp" android:layout_height="65dp" android:id="@+id/imagebutton" android:src="@drawable/ic_pin_drop_black_24dp" /> </relativelayout>
mapsactivity.java
import android.app.activity; import android.content.intent; import android.support.v4.app.fragmentactivity; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.view; import android.widget.button; import android.widget.imagebutton; import android.widget.textview; import android.widget.toast; import android.widget.zoombutton; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.mapfragment; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.supportmapfragment; import android.app.appopsmanager; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; import com.google.android.gms.appindexing.action; import com.google.android.gms.appindexing.appindex; import com.google.android.gms.common.api.googleapiclient; public class mapsactivity extends fragmentactivity implements onmapreadycallback { private googlemap mmap; imagebutton floatbutton; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_maps); floatbutton = (imagebutton) findviewbyid(r.id.imagebutton); floatbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intent = new intent(mapsactivity.this,secondactivity.class); startactivity(i); } }); // obtain supportmapfragment , notified when map ready used. supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); } /** * manipulates map once available. * callback triggered when map ready used. * can add markers or lines, add listeners or move camera. in case, * add marker near sydney, australia. * if google play services not installed on device, user prompted install * inside supportmapfragment. method triggered once user has * installed google play services , returned app. */ @override public void onmapready(googlemap googlemap) { mmap = googlemap; mmap.movecamera(cameraupdatefactory.newlatlngzoom(new latlng (6.5084, 3.3842), 14)); } }
i created second activity activty_second.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:map="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/map" android:name="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mapsactivity" tools:layout="@android:layout/simple_spinner_dropdown_item" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="lagos mainland" android:padding="8dp" android:background="#53fed0" android:id="@+id/buttonmaps" android:layout_marginleft="90dp" android:layout_marginstart="90dp" android:layout_alignparenttop="true" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hospital" android:id="@+id/buttonmaps2" android:layout_margintop="35dp" android:layout_below="@+id/buttonmaps" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:clickable="true" android:background="@color/coloraccent" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="bus stops" android:id="@+id/buttonmaps3" android:clickable="true" android:layout_margintop="35dp" android:background="@color/coloraccent" android:layout_below="@+id/buttonmaps2" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="taxi" android:id="@+id/buttonmaps4" android:layout_below="@+id/buttonmaps3" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_margintop="35dp" android:clickable="true" android:background="@color/coloraccent" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="gas station" android:id="@+id/buttonmaps5" android:layout_margintop="35dp" android:clickable="true" android:background="@color/coloraccent" android:layout_below="@+id/buttonmaps4" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="park" android:id="@+id/buttonmaps6" android:layout_margintop="35dp" android:clickable="true" android:background="@color/coloraccent" android:layout_below="@+id/buttonmaps5" android:layout_alignparentleft="true" android:layout_alignparentstart="true" /> </linearlayout>
secondactivity.java
import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.view.view; import android.widget.button; import android.widget.imagebutton; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.onmapreadycallback; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.bitmapdescriptorfactory; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; public class secondactivity extends fragmentactivity implements onmapreadycallback { private googlemap mmap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activty_second); final button button1 = (button) findviewbyid(r.id.buttonmaps); final button button2 = (button) findviewbyid(r.id.buttonmaps2); final button button3 = (button) findviewbyid(r.id.buttonmaps3); final button button4 = (button) findviewbyid(r.id.buttonmaps4); final button button5 = (button) findviewbyid(r.id.buttonmaps5); final button button6 = (button) findviewbyid(r.id.buttonmaps6); imagebutton floatbutton; floatbutton = (imagebutton) findviewbyid(r.id.imagebutton); floatbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { button1.isshown(); button2.isshown(); button3.isshown(); button4.isshown(); button5.isshown(); button6.isshown(); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { mmap.clear(); if (button1.isshown()) { mmap.addmarker(new markeroptions().position(new latlng()).title("").snippet("my location").icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher))); } } }); button2.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mmap.clear(); if (button2.isshown()) { mmap.addmarker(new markeroptions().position(new latlng()).title("").icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher_hospital))); mmap.movecamera(cameraupdatefactory.newlatlngzoom(new latlng(6.5084, 3.3842), 14)); } } }); button3.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mmap.clear(); if (button3.isshown()) { mmap.addmarker(new markeroptions().position(new latlng()).title("").icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher_busstop))); } } }); button4.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { mmap.clear(); if (button4.isshown()) { mmap.addmarker(new markeroptions().position(new latlng()).title("").icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher_taxi))); mmap.movecamera(cameraupdatefactory.newlatlngzoom(new latlng(6.5084, 3.3842), 14)); } } }); button5.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { mmap.clear(); if (button5.isshown()) { mmap.addmarker(new markeroptions().position(new latlng()).title("").icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher_gas))); } } }); button6.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { mmap.clear(); if (button6.isshown()) { mmap.addmarker(new markeroptions().position(new latlng()).title("").icon(bitmapdescriptorfactory.fromresource(r.mipmap.ic_launcher_park))); } } }); } }); // obtain supportmapfragment , notified when map ready used. supportmapfragment mapfragment = (supportmapfragment) getsupportfragmentmanager() .findfragmentbyid(r.id.map); mapfragment.getmapasync(this); }
my android manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> android:theme="@android:style/apptheme" <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.write_external_storage"/> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices"/> <!-- access_coarse/fine_location permissions not required use google maps android api v2, must specify either coarse or fine location permissions 'mylocation' functionality. --> <uses-permission android:name="android.permission.access_fine_location" /> <uses-permission android:name="android.permission.access_coarse_location" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="android map" android:supportsrtl="true" android:theme="@style/apptheme"> android:name="android.support.multidex.multidexapplication"> <!-- api key google maps-based apis defined string resource. (see file "res/values/google_maps_api.xml"). note api key linked encryption key used sign apk. need different api key each encryption key, including release key used sign apk publishing. can define keys debug , release targets in src/debug/ , src/release/. --> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="" /> <activity android:name=".mapsactivity" android:label="map"> <activity android:name=".secondactivity"/> </activity> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </application> </manifest>
please
here crashlog
fatal exception: main android.content.activitynotfoundexception: unable find explicit activity class {com.example.user.naviapp/com.example.user.naviapp.secondactivity}; have declared activity in androidmanifest.xml? @ android.app.instrumentation.checkstartactivityresult(instrumentation.java:1512) @ android.app.instrumentation.execstartactivity(instrumentation.java:1388) @ android.app.activity.startactivityforresult(activity.java:3190) @ android.support.v4.app.fragmentactivity.startactivityforresult(fragmentactivity.java:871) @ android.app.activity.startactivity(activity.java:3297) @ com.example.user.naviapp.mapsactivity$1.onclick(mapsactivity.java:49) @ android.view.view.performclick(view.java:3558) @ android.view.view$performclick.run(view.java:14157) @ android.os.handler.handlecallback(handler.java:605) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4514) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:790) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:557) @ dalvik.system.nativestart.main(native method)
you declared activity in manifest in wrong way, this:
<activity android:name=".mapsactivity" android:label="map"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".secondactivity"/>
Comments
Post a Comment