GoogleマップをXamarin Androidに統合しようとしています。しかし、タイトルに書かれているようにエラーを受け取りました。このエラーは私のSetContentView(Resource.Layout.Main)に現れました。以下のように:マップの処理されない例外:Android.Views.InflateException:バイナリXMLファイル行#1:バイナリXMLファイル行#1:クラスフラグメントのエラーエラーが発生しました
Error occurred in MainActivity.cs
マイGoogle Playのサービスは、最新です。私は、プロジェクトを再構築しようとしましたが、VSを再起動しても私にとってはうまくいかなかったのです。フォーラムのうち、私の質問に答えてくれた人はいなかった。
MainActivity.cs
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Gms.Maps;
namespace Google_maps.Droid
{
[Activity (Label = "@string/Google_maps.Android", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity, IOnMapReadyCallback
{
private GoogleMap mMap;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
SetUpMap();
}
private void SetUpMap()
{
if (mMap == null)
{
FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map).GetMapAsync(this);
}
}
public void OnMapReady(GoogleMap googleMap)
{
mMap = googleMap;
}
}
}
Main.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
のstrings.xml
:これらはのために私のプロジェクトで書かれているものです0
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, Click Me!</string>
<string name="app_name">Google_maps.Android</string>
<string name="google_maps_key">my_API_key</string>
<string name="Google_maps.Android">Google maps</string>
</resources>
と追加情報については最終的には、
のAndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Google_maps.google_mapsAndroid" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="15" />
<application android:label="Google_maps.Android" android:icon="@drawable/Icon">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.android.maps.V2.API_KEY" android:value="@string/google_maps_key" />
</application>
<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" />
</manifest>
、私は彼がどのようにセットアップする上で私たちに教えてジョー・ロック、youtubeにからの方法に従っグーグルマップ。ここで彼のビデオへのリンクは次のとおりです。
https://www.youtube.com/watch?v=W6Q0olRPsus
あなたはコメントセクションを下に見てみると、あなたは多くの人があまりにも同じ問題を抱えている見ることができます。このビデオは2年前にとなったので、なぜこの現状ではうまくいかないのか分かります。しかし、もしあなたが私のアンドロイドモバイルアプリケーションにGoogleマップを統合するための適切な方法を教えてくれれば、私はそれを感謝します。何とかすれば、この方法はもはや信頼できるものではありません。前もって感謝します。
について、 ザマリンとプログラミング初心者。
編集:それは レイアウトリソース上の活動内容を設定無効Activity.SetContentView(int型LayoutResID)(2つの過負荷)と言う
私は、マウスをドラッグしSetContentView (Resource.layout.Main)
に。
私はこれについて心配すべきでしょうか?
一般に、フラグメンテーションは、アクティビティを拡張するクラス内に埋め込むことはできません。その代わりに、FragmentActivityは – Dinash
でなければなりません。 –
'public class MainActivity:Activity'を 'public class MainActivity:FragmentActivity'に変更し、適切なimport文を追加してください。 – Dinash