我正在使用SupportMapFragment,并且在我测试过的每台设备上都运行良好。我收到了一个java.io.FileNotFoundException的错误报告,其中包含以下内容:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.koosprozinski.westernwheels/com.koosprozinski.westernwheels.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2098)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1204)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4945)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:408)
at android.app.Activity.setContentView(Activity.java:2050)
at com.koosprozinski.westernwheels.MainActivity.onCreate(MainActivity.java:40)
at android.app.Activity.performCreate(Activity.java:5202)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1082)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2037)
... 11 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/maps_btn_myl.xml from drawable resource ID #0x7f020115
at android.content.res.Resources.loadDrawable(Resources.java:1957)
at android.content.res.Resources.getDrawable(Resources.java:673)
at maps.ai.a.c(Unknown Source)
at maps.af.al.a(Unknown Source)
at maps.af.be.a(Unknown Source)
at maps.af.bd.a(Unknown Source)
at cmi.onTransact(SourceFile:107)
at android.os.Binder.transact(Binder.java:326)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.a$4.b(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
... 21 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi-v14/maps_btn_myl_pressed.png from drawable resource ID #0x7f020117
at android.content.res.Resources.loadDrawable(Resources.java:1974)
at android.content.res.Resources.getDrawable(Resources.java:673)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:881)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
at android.content.res.Resources.loadDrawable(Resources.java:1954)
... 40 more
Caused by: java.io.FileNotFoundException: res/drawable-hdpi-v14/maps_btn_myl_pressed.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:407)
at android.content.res.Resources.loadDrawable(Resources.java:1966)
... 45 more
这是我的主要活动xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
到底能造成什么?据我所知,绝大多数用户没有遇到这种情况,我想不出任何方法可以尝试复制它。
答案 0 :(得分:4)
我建议你这样做:
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
不是android:name。如果有效,请告诉我。
答案 1 :(得分:4)
尝试以下方法,它对我有用:
<application>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API KEY" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
答案 2 :(得分:4)
这是解决方案! NullPointerException from Google maps 如果没有内置卡,请插入SD卡!自2013年以来,谷歌一直没有解决这个问题。
答案 3 :(得分:0)
在您的主要活动xml上,更改android:name="com.google.android.gms.maps.SupportMapFragment"
到此:
class="com.google.android.gms.maps.SupportMapFragment"