地图的棉花糖碎片活动中的崩溃

时间:2015-12-18 08:30:48

标签: android google-maps android-fragmentactivity

我正在使用fragmentActivity for maps.In Java类在setContentView上获取错误。我的Mapscreen.java就像:它在某些设备上工作正常,只显示棉花糖崩溃。或者还有其他原因吗?

public class MapScreen extends FragmentActivity implements LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {

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

    SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    googleMap = fm.getMap();
}

    and my xml has fragment using SupportMapFragment as well. map_screen.xml is like :


    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

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

        <ImageView
            android:id="@+id/startActivityButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginLeft="50dp"
           android:layout_marginRight="50dp"
            android:layout_marginBottom="44dp"
           android:background="@drawable/end_meetup_btn"
         />

    </RelativeLayout>

我无法找到相同的问题在Marshmallow中遇到崩溃:&#34;二进制XML文件行#7:错误膨胀类片段&#34;请提出建议! 试图找到&#34;引起:java.lang.NullPointerException:尝试调用虚方法&#39; boolean java.io.File.mkdir()&#39;在null对象引用&#34;还

    12-18 13:40:14.425: E/AndroidRuntime(8026): FATAL EXCEPTION: main
    12-18 13:40:14.425: E/AndroidRuntime(8026): Process: com.kindlebit.urban_exchange, PID: 8026
    12-18 13:40:14.425: E/AndroidRuntime(8026): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kindlebit.urban_exchange/com.kindlebit.urban_exchange.MapScreen}: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.ActivityThread.-wrap11(ActivityThread.java)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.os.Handler.dispatchMessage(Handler.java:102)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.os.Looper.loop(Looper.java:148)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.ActivityThread.main(ActivityThread.java:5417)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at java.lang.reflect.Method.invoke(Native Method)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    12-18 13:40:14.425: E/AndroidRuntime(8026): Caused by: android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:393)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.Activity.setContentView(Activity.java:2166)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.kindlebit.urban_exchange.MapScreen.onCreate(MapScreen.java:109)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.Activity.performCreate(Activity.java:6237)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     ... 9 more
    12-18 13:40:14.425: E/AndroidRuntime(8026): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     ... 17 more
    12-18 13:40:14.425: E/AndroidRuntime(8026): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.mkdir()' on a null object reference
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.gmm6.m.ad.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.gmm6.c.y.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.e.bd.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.e.z.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.maps.api.android.lib6.e.y.a(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.os.Binder.transact(Binder.java:387)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.dynamic.zza.zza(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1185)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1287)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2243)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:278)
    12-18 13:40:14.425: E/AndroidRuntime(8026):     at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)

5 个答案:

答案 0 :(得分:4)

问题出在&#34; Micro-max Android one mobile&#34;这是6.0棉花糖。 此设备没有足够的内部或外部存储空间。即使没有SD卡。

乔治中回答:

NullPointerException from Google maps

我安装了存储卡,现在崩溃了。

所以我发现问题是更新了Google Play服务,这些服务需要我的设备中不够的Space(更新后的Google照片)。

并且还有一个错误行显示&#34;引起:java.lang.NullPointerException:尝试调用虚方法&#39; boolean java.io.File.mkdir()&#39;在null对象引用&#34;

我决定在安装SD卡后检查。它工作了

答案 1 :(得分:1)

<!-- EXTERNAL_STORAGE permissions are optional for Android 6.0 onwards. -->
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="22" />
    <uses-permission
        android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="22" />

将此添加到您的清单中。也许地图需要sdcard权限才能获得一些额外的缓存或其他东西。

答案 2 :(得分:1)

此问题已在Google Play服务库9.0.83版中修复。

答案 3 :(得分:0)

这只是我做的一个解决方法。如果下面的检查失败,我加载了一个错误的片段,而不是加载地图。

/** Checks if external storage is available for read and write */
public boolean isExternalStorageWritable() {
    String state = Environment.getExternalStorageState();
    return Environment.MEDIA_MOUNTED.equals(state);
}

答案 4 :(得分:0)

将SD卡权限添加到清单文件中。

    <uses-permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
     />

    <uses-permission
    android:name="android.permission.READ_EXTERNAL_STORAGE"
    />