我正在尝试运行com.akexorcist.googledirection
demo from here
我正在使用Android Studio
和模拟器API version 23
。我根本没有修改应用程序,它构建并运行正常,但是当我点击主屏幕上的任何按钮时它会崩溃。
我尝试在SimpleDirectionActivity
onCreate
方法中添加断点,它在我检查过的setContentView(R.layout.activity_simple_direction);
行崩溃,布局中出现activity_simple_direction.xml
。
activity_simple_direction.xml
看起来如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SimpleDirectionActivity">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<Button
android:id="@+id/btn_request_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/request_direction" />
</RelativeLayout>
完整堆栈跟踪如下所示:
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: FATAL EXCEPTION: main
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: Process: com.akexorcist.googledirection.sample, PID: 3806
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.akexorcist.googledirection.sample/com.akexorcist.googledirection.sample.AlternativeDirectionActivity}: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class fragment
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class fragment
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.akexorcist.googledirection.sample.AlternativeDirectionActivity.onCreate(AlternativeDirectionActivity.java:37)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class fragment
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.akexorcist.googledirection.sample.AlternativeDirectionActivity.onCreate(AlternativeDirectionActivity.java:37)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6237)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.-wrap11(ActivityThread.java)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.File.mkdir()' on a null object reference
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.gmm6.m.ad.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.gmm6.c.h.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.gmm6.c.ao.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.e.bd.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.e.ev.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.e.z.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.maps.api.android.lib6.e.y.a(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.maps.internal.u.onTransact(SourceFile:107)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.os.Binder.transact(Binder.java:387)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.dynamic.zza.zza(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1036)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1226)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1328)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2284)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111)
01-20 21:19:56.368 3806-3806/com.akexorcist.googledirection.sample E/AndroidRuntime: at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(Frag
01-20 21:20:00.559 3806-3806/? I/Process: Sending signal. PID: 3806 SIG: 9
以前有人见过这个错误吗?为什么会失败?
答案 0 :(得分:2)
如果您使用compile 'com.google.android.gms:play-services:8.4.0'
,请查看此帖子gmaps-issues
事实上,手机中需要SD卡才能解决此问题,对于模拟器,您可以直接在高级设置中添加SD卡。
希望它有所帮助,