Android谷歌地图

Android谷歌地图,第1张

概述我尝试在我的应用程序中添加GoogleMAPApiv2.但我得到例外.例外是java.lang.RuntimeException:UnabletostartactivityComponentInfo{info.androidhive.googlemapsv2/info.androidhive.googlemapsv2.MainActivity}:android.view.InflateException:BinaryXMLfileline

我尝试在我的应用程序中添加Google MAP API v2.但我得到例外.例外是

 java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androIDhive.Googlemapsv2/info.androIDhive.Googlemapsv2.MainActivity}: androID.vIEw.InflateException: Binary XML file line #5: Error inflating class fragment

这是我的xml类

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="fill_parent"    androID:layout_height="fill_parent" >    <fragment        androID:ID="@+ID/map"        androID:name="com.Google.androID.gms.maps.MapFragment"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"/></relativeLayout>

这是我的主要课程

public class MainActivity extends Activity {    private GoogleMap _GoogleMap=null;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        try        {            //loading map            initilizeMap();            _GoogleMap.setMapType(GoogleMap.MAP_TYPE_norMAL);            _GoogleMap.setMyLocationEnabled(true);               } catch (Exception e) {            e.printstacktrace();        }    }    private voID initilizeMap() {        if(_GoogleMap==null)        {            _GoogleMap=((MapFragment)getFragmentManager().findFragmentByID(R.ID.map)).getMap();            if (_GoogleMap == null) {                Toast.makeText(getApplicationContext(),                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)                        .show();            }        }    }    @OverrIDe    protected voID onResume() {        // Todo auto-generated method stub        super.onResume();        initilizeMap();    }}

这是我的logcat

01-31 14:20:55.603: E/AndroIDRuntime(311): FATAL EXCEPTION: main01-31 14:20:55.603: E/AndroIDRuntime(311): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demo/com.example.demo.MainActivity}: androID.vIEw.InflateException: Binary XML file line #6: Error inflating class fragment01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2663)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.ActivityThread.access00(ActivityThread.java:125)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.os.Handler.dispatchMessage(Handler.java:99)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.os.Looper.loop(Looper.java:123)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.ActivityThread.main(ActivityThread.java:4627)01-31 14:20:55.603: E/AndroIDRuntime(311):  at java.lang.reflect.Method.invokeNative(Native Method)01-31 14:20:55.603: E/AndroIDRuntime(311):  at java.lang.reflect.Method.invoke(Method.java:521)01-31 14:20:55.603: E/AndroIDRuntime(311):  at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)01-31 14:20:55.603: E/AndroIDRuntime(311):  at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:626)01-31 14:20:55.603: E/AndroIDRuntime(311):  at dalvik.system.NativeStart.main(Native Method)01-31 14:20:55.603: E/AndroIDRuntime(311): Caused by: androID.vIEw.InflateException: Binary XML file line #6: Error inflating class fragment01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:576)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:618)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:407)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:320)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:276)01-31 14:20:55.603: E/AndroIDRuntime(311):  at com.androID.internal.policy.impl.PhoneWindow.setContentVIEw(PhoneWindow.java:198)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.Activity.setContentVIEw(Activity.java:1647)01-31 14:20:55.603: E/AndroIDRuntime(311):  at com.example.demo.MainActivity.onCreate(MainActivity.java:22)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2627)01-31 14:20:55.603: E/AndroIDRuntime(311):  ... 11 more01-31 14:20:55.603: E/AndroIDRuntime(311): Caused by: java.lang.classNotFoundException: androID.vIEw.fragment in loader dalvik.system.PathClassLoader[/data/app/com.example.demo-2.apk]01-31 14:20:55.603: E/AndroIDRuntime(311):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)01-31 14:20:55.603: E/AndroIDRuntime(311):  at java.lang.classLoader.loadClass(ClassLoader.java:573)01-31 14:20:55.603: E/AndroIDRuntime(311):  at java.lang.classLoader.loadClass(ClassLoader.java:532)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.createVIEw(LayoutInflater.java:466)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.onCreateVIEw(LayoutInflater.java:544)01-31 14:20:55.603: E/AndroIDRuntime(311):  at com.androID.internal.policy.impl.PhoneLayoutInflater.onCreateVIEw(PhoneLayoutInflater.java:66)01-31 14:20:55.603: E/AndroIDRuntime(311):  at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:563)

解决方法:

您应该使用SupportMapFragment而不是MapFragment.

更改

<fragment    androID:ID="@+ID/map"    androID:name="com.Google.androID.gms.maps.MapFragment"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"/>

<fragmentandroID:ID="@+ID/map"androID:name="com.Google.androID.gms.maps.SupportMapFragment"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"/>

也改变

   _GoogleMap=((MapFragment)getFragmentManager().findFragmentByID(R.ID.map)).getMap();

_GoogleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentByID(        R.ID.map)).getMap(); 

而且如果你在旧设备上使用片段(precomb之前),你应该始终从FragmentActivity扩展你的Activity.

并检查

将Google Play服务版本添加到您应用的清单中

Edit your application’s AndroIDManifest.xml file, and add the
following declaration within the element. This embeds the version of
Google Play services that the app was compiled with.

您只需添加<元数据>在< application>下标记到您的AndroIDManifest.xml中

....<application><Meta-data androID:name="com.Google.androID.gms.version"   androID:value="@integer/Google_play_services_version" /></application>

这是因为最新的Google Play服务需要版本名称,使用< Meta-data .. />来提及.在AndroIDManifest.xml中

总结

以上是内存溢出为你收集整理的Android谷歌地图全部内容,希望文章能够帮你解决Android谷歌地图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1101713.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存