2016-10-05 6 views
0

私の問題は何か分かりませんが、これはうまくいきます。だから私は、このActivityクラスのMainMapActivityandroid.view.InflateException:クラス・フラグメントを拡張するエラー

public class MainMapActivity extends AppCompatActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main_nav); 

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

activity_main_nav

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <include xmlns:android="http://schemas.android.com/apk/res/android" 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

    <include 
     layout="@layout/activity_main_map" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

と含ま

activity_main_map
<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:layout_marginBottom="15dp" 
android:layout_marginLeft="15dp" 
android:layout_marginRight="15dp" 
android:layout_marginTop="15dp" 
android:name="com.google.android.gms.maps.SupportMapFragment"/> 

誰か缶を持っています私の問題を助けてくれますか?私はひどく答えが必要です。ありがとう!

答えて

1

私はかつてこのような問題に遭遇し、XMLのフラグメントにname属性を追加しました。

<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/map" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" 
    android:name="com.testing.svma.MainActivity"/> 

問題を解決する可能性があります。

また、次のことを確認してください。

  1. マップ
  2. ために必要なアクセス許可のためのマニフェストをチェックしたメタデータホープ、このことができます

権利であることを確認してください。

P.S:問題は、APIレベルまたは再生サービスのバージョンでも発生する可能性があります。

+0

こんにちは@san私は既に私のコードを変更しない別のデバイスから私のプロジェクトを実行しようとしました。それはSamsung Androidバージョン5.1.1で正常に動作します。しかし、私の携帯電話はAsusと、5.1.1のAndroidのバージョンはなぜ私がAsus上で私のアプリケーションを実行すると、そのエラーを示しているのですか?しかし、4.4.2のAndroidバージョンを搭載した他のブランドの携帯電話でも、正常に動作します。 – tin

+0

あなたは何らかの理由で私がそのエラーに遭遇した理由を知っていますか? – tin

+0

Androidは不思議なやり方で動作し、それぞれのデバイスメーカーはGoogleの処女OSに自分の編集を重ね合わせて独自のバージョンのOSを作成し、一部は自分の仕事ではあまりにも恥ずかしいかもしれません。それが奇妙な行動の理由かもしれない。あなたが私に完全なスタックトレースを送ることができるなら、私はあなたをもっと助けることができるでしょう... – San

関連する問題