1

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)に。

私はこれについて心配すべきでしょうか?

+0

一般に、フラグメンテーションは、アクティビティを拡張するクラス内に埋め込むことはできません。その代わりに、FragmentActivityは – Dinash

+0

でなければなりません。 –

+0

'public class MainActivity:Activity'を 'public class MainActivity:FragmentActivity'に変更し、適切なimport文を追加してください。 – Dinash

答えて

1

私のプロジェクトを再作成する必要が生じた場合は、最初からプロジェクトを開くことができませんでした。私はエミュレータを変更しました。これは今まで問題になっていたかもしれないと思っていましたが、それを動作させてタイトルのエラーを取り除くことができました。

現在の唯一の問題は、左下に「google」ロゴが表示されていますが、地図は表示されないことです。私はおそらく別のスレッドでこれを記述する必要がありますか?以来、今は別のケースです。

これまでのところ、エラーは取り除かれました。これはデバイスとアンドロイドのバージョンがこれで大きな役割を果たしていると私は信じています。

EDIT:

こんにちは、再度、私はGoogleマップは完全に私のアプリに取り組んで得ることができました。私が前に言ったように、「デバイスとアンドロイド版は、アプリケーションを開発する上で大きな役割を果たします」参考までに、Androidバージョン7.1(Nougat)、Nexus 5端末、Google API x86 - API 25を使用しています。

  1. プロパティ>>アプリケーションでコンパイラを8.0(Oreo)に設定し、プロパティ>> Androidマニフェストで[SDKバージョンを使用してコンパイルを使用する]を設定します。

  2. 最新の安定版ツールで見つかったNuGetパッケージマネージャ、からXamarin社があなたのGoogleマップパッケージを更新します。最新の安定版は42.1021.1です。 最新の安定版ツールで見つかったNugetパッケージマネージャからXamarin社あなたのXamarin.Android.Support.Compat、

  3. 更新。現在の最新の安定版は26.0.2です。フラグメントライブラリがこれと共に更新されない場合は、手動で更新してください。以下に示すように

  4. 私はおそらく不足している権限を追加しました:

<permission android:name="googleMapsProject.googleMapsProject.droid.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> 
 
\t <uses-permission android:name="com.deg.blubcnmobl.droid.permission.MAPS_RECEIVE" />

をFYI googleMapsProject.googleMapsProjectは、あなたのパッケージ名です。大文字で始まらず、Googleコンソールの[Key Restriction]ページで作成したパッケージ名と一致することを確認してください。

  1. これはv2のGoogleマップAPIで実行されています。

これは、私がそれをどのように動作させるかです。お役に立てれば!

0

試してみてください。

変更:

<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:name="com.google.android.gms.maps.MapFragment"/> 

へ:以下

<fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:name="com.google.android.gms.maps.SupportMapFragment"/> 

また、あなたのSetUpMapで()メソッドの変更:

FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map).GetMapAsync(this); 

用:

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
       .findFragmentById(R.id.map); 
     mapFragment.getMapAsync(this); 
Nuget

2.Use AppCompatActivity代わりの活動から

0

1.Install Appcompact dllをあなたの特性の下

3.AddあなたAndroidManifestで次の権限を

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.INSTALL_LOCATION_PROVIDER"/> 
<uses-permission android:name="android.permission.CONTROL_LOCATION_UPDATES"/> 
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/> 

4.Addあなたのmain.axmlに続くxml

<fragment 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.MapFragment" /> 

5.Addリソース/値/スタイルの下であなたのstyles.xmlに次のコード:

<style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> 
<item name="windowNoTitle">true</item> 
<item name="windowActionBar">false</item> 
<item name="colorPrimary">#FFCC01</item> 
<item name="colorPrimaryDark">#E69D02</item> 
<item name="colorControlHighlight">#FFCC01</item> 
<item name="colorAccent">#D5012A</item> 
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item> 
</style> 

<style name="DrawerArrowStyle" 
    parent="@style/Widget.AppCompat.DrawerArrowToggle"> 
    <item name="spinBars">true</item> 
    <item name="color">@color/colorRedText</item> 
</style> 

<style name="MyTheme" parent="MyTheme.Base"> 
</style> 

あなたのAndroidManifest.xmlファイルに以下の行を追加して、デフォルトのアプリケーションをテーマとしての私のテーマ6.Makeいるあなたを現在のアンドロイドプロジェクトの下に、あなたのプロジェクトのプロパティで見つけることができます。

<application android:label="YourAppName" android:theme="@style/MyTheme" android:hardwareAccelerated="true" android:largeHeap="true" android:icon="@drawable/YourAppIcon"> 

そして場合には、あなたは、単にここでチェックできるもの理解しない:

https://developer.xamarin.com/guides/android/platform_features/maps_and_location/

をあなたがVS-でツールバーに見つけることができますあなたのAndroidSdkで、Googleのプレイサービスを持っている場合にも確認してください15個のツール> Android> AndroidSdk エクストラの下にGoogle Playサービスをインストールします。

+0

@ G.hakimに応答していただきありがとうございます。 **未処理の例外: Java.Lang.IllegalStateException:しかし私は、 'SetContentView(Resource.layout.Main)' エラーに新しいエラーに投げ、この方法を試してみたあなたはTheme.AppCompatを使用する必要がありますこのアクティビティのテーマ(または子孫)。発生した**。 また、マウスを 'SetContentView(Resource.layout.Main) 'にドラッグすると、** void Activity.SetContentView(int LayoutResID)(+2オーバーロード) レイアウトリソースのアクティビティコンテンツが設定されます。** 私はこれについて心配すべきでしょうか? –

+0

上記のコードに従って更新すると、既定のテーマを持たないため、私の回答を見て回りますが、エラーはありません@BahAkif –

+0

私たちはほとんどそこにいると思います。 ** styles.xml **に現れたエラーが1つあります。エラーが表示されています。 **指定された名前に一致するリソースが見つかりませんでした(値 '@ style/DrawerArrowStyle'の 'drawerArrowStyle')**。 ** Android Support Library v7 AppCompat **と呼ばれるコンポーネントを使用しており、** Xamarin.Android.Support.v7.AppCompat **と呼ばれるナゲットパッケージを** Xamarin.inc **でインストールしています。適切なパッケージとコンポーネントをダウンロードしていますか? –

関連する問題