google api - Error with SupportMapFragment in Android Studio on a Fragment -
i have searched many hours , days find answer this, still cannot. using android studio (latest ver) ide
i trying create map view (using google maps api) fragment part of fragmentactivity.
androidmanifest updated necessary permissions , google key.
as can see @ output, latlng class google map api working creating instance. lib imported on libs folder
please !!
edit: found instructions how build google play services (google maps) under android studio
fragment_mapview_gmaps.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".showactivity" > <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.supportmapfragment"/> </relativelayout>
mapviewfragment
public class mapviewfragment extends fragment { private static view view; private context context; public static googlemap map = null; public mapviewfragment() { this.context = getactivity(); loadmapfragment(); } private void loadmapfragment() { } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { if (view != null) { viewgroup parent = (viewgroup) view.getparent(); if (parent != null) parent.removeview(view); } try { latlng slatlng = new latlng(37.857236, -122.486916); system.out.println("debug: "+ slatlng.tostring()); view = inflater.inflate(r.layout.fragment_mapview_gmaps, container, false); } catch (inflateexception e) { system.out.println("error: " + e.getmessage()); /* map there, return view */ } return view; } }
mainactivity.java
public class mainactivity extends fragmentactivity implements actionbar.tablistener { /** * {@link android.support.v4.view.pageradapter} provide * fragments each of sections. use * {@link android.support.v4.app.fragmentpageradapter} derivative, * keep every loaded fragment in memory. if becomes memory * intensive, may best switch * {@link android.support.v4.app.fragmentstatepageradapter}. */ sectionspageradapter msectionspageradapter; /** * {@link viewpager} host section contents. */ viewpager mviewpager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // set action bar. final actionbar actionbar = getactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); // create adapter return fragment each of 3 // primary sections of app. msectionspageradapter = new sectionspageradapter(getsupportfragmentmanager()); // set viewpager sections adapter. mviewpager = (viewpager) findviewbyid(r.id.pager); mviewpager.setadapter(msectionspageradapter); // when swiping between different sections, select corresponding // tab. can use actionbar.tab#select() if have // reference tab. mviewpager.setonpagechangelistener(new viewpager.simpleonpagechangelistener() { @override public void onpageselected(int position) { actionbar.setselectednavigationitem(position); } }); // each of sections in app, add tab action bar. (int = 0; < msectionspageradapter.getcount(); i++) { // create tab text corresponding page title defined // adapter. specify activity object, implements // tablistener interface, callback (listener) when // tab selected. actionbar.addtab( actionbar.newtab() .settext(msectionspageradapter.getpagetitle(i)) .settablistener(this)); } } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public void ontabselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { // when given tab selected, switch corresponding page in // viewpager. mviewpager.setcurrentitem(tab.getposition()); } @override public void ontabunselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { } @override public void ontabreselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { } /** * {@link fragmentpageradapter} returns fragment corresponding * 1 of sections/tabs/pages. */ public class sectionspageradapter extends fragmentpageradapter { public sectionspageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int position) { // getitem called instantiate fragment given page. // return dummysectionfragment (defined static inner class // below) page number lone argument. /*fragment fragment = new dummysectionfragment(); bundle args = new bundle(); args.putint(dummysectionfragment.arg_section_number, position + 1); fragment.setarguments(args); return fragment;*/ fragment fragment; switch (position) { case 0: //list view fragment = new listviewfragment(); break; default: //map view fragment = new mapviewfragment(); break; } return fragment; } @override public int getcount() { // show 2 total pages. return 2; } @override public charsequence getpagetitle(int position) { locale l = locale.getdefault(); switch (position) { case 0: return getstring(r.string.title_section0).touppercase(l); case 1: return getstring(r.string.title_section1).touppercase(l); } return null; } } }
this output
07-21 12:27:15.581 8768-8768/com.xxxx.cs.csitsclocator i/system.out: listviewfragment.onactivitycreated 07-21 12:27:15.581 8768-8768/com.xxxx.cs.csitsclocator i/system.out: listviewfragment.oncreateloader 07-21 12:27:15.591 8768-8768/com.xxxx.cs.csitsclocator i/system.out: debug: lat/lng: (37.857236,-122.486916) 07-21 12:27:15.591 8768-8768/com.xxxx.cs.csitsclocator w/dalvikvm: vfy: unable resolve static field 1062 (mapattrs) in lcom/google/android/gms/r$styleable; 07-21 12:27:15.591 8768-8768/com.xxxx.cs.csitsclocator d/dalvikvm: vfy: replacing opcode 0x62 @ 0x000e 07-21 12:27:15.601 8768-8768/com.xxxx.cs.csitsclocator d/androidruntime: shutting down vm 07-21 12:27:15.601 8768-8768/com.xxxx.cs.csitsclocator w/dalvikvm: threadid=1: thread exiting uncaught exception (group=0x41003930) 07-21 12:27:15.601 8768-8786/com.xxxx.cs.csitsclocator i/system.out: listvewloaderasynctask.loadinbackground 07-21 12:27:15.601 8768-8768/com.xxxx.cs.csitsclocator e/androidruntime: fatal exception: main java.lang.noclassdeffounderror: com.google.android.gms.r$styleable @ com.google.android.gms.maps.googlemapoptions.createfromattributes(unknown source) @ com.google.android.gms.maps.supportmapfragment.oninflate(unknown source) @ android.support.v4.app.fragmentactivity.oncreateview(fragmentactivity.java:279) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:676) @ android.view.layoutinflater.rinflate(layoutinflater.java:746) @ android.view.layoutinflater.inflate(layoutinflater.java:489) @ android.view.layoutinflater.inflate(layoutinflater.java:396) @ com.xxxx.cs.csitsclocator.tabmapview.mapviewfragment.oncreateview(mapviewfragment.java:59) @ android.support.v4.app.fragment.performcreateview(fragment.java:1460) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:911) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1088) @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682) @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1444) @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:461) @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141) @ android.support.v4.view.viewpager.populate(viewpager.java:1064) @ android.support.v4.view.viewpager.populate(viewpager.java:911) @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1432) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ android.view.view.measure(view.java:15518) @ android.widget.linearlayout.measurevertical(linearlayout.java:847) @ android.widget.linearlayout.onmeasure(linearlayout.java:588) @ android.view.view.measure(view.java:15518) @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4825) @ android.widget.framelayout.onmeasure(framelayout.java:310) @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2176) @ android.view.view.measure(view.java:15518) @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1874) @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1089) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1265) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:989) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:4351) @ android.view.choreographer$callbackrecord.run(choreographer.java:749) @ android.view.choreographer.docallbacks(choreographer.java:562) @ android.view.choreographer.doframe(choreographer.java:532) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:735) @ android.os.handler.handlecallback(handler.java:725) @ android.os.handler.dispatchmessage(handler.java:92) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:5041) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) @ dalvik.system.nativestart.main(native method) 07-21 12:27:15.621 1208-1208/? w/activitymanager: force finishing activity com.xxxx.cs.csitsclocator/.mainactivity
lib imported on libs folder
the play services sdk android library project, not jar. remove jar libs/
, add reference android library project. way, pick resources defined library project.
Comments
Post a Comment