2016-02-07 59 views
0

我收到的時候我嘗試在Android應用程序在Android中創建地圖。錯誤mainactivity.java

02-06 20:38:48.178 15186-15186/? E/AndroidRuntime: FATAL EXCEPTION: main 
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.agupta.routebus/com.example.agupta.routebus.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
     at android.app.ActivityThread.access$600(ActivityThread.java:141) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
     at android.os.Handler.dispatchMessage(Handler.java:99) 
     at android.os.Looper.loop(Looper.java:137) 
     at android.app.ActivityThread.main(ActivityThread.java:5041) 
     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:793) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
     at dalvik.system.NativeStart.main(Native Method) 
    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256) 
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109) 
     at com.example.agupta.routebus.MainActivity.onCreate(MainActivity.java:29) 
     at android.app.Activity.performCreate(Activity.java:5104) 
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)  
     at android.app.ActivityThread.access$600(ActivityThread.java:141)  
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)  
     at android.os.Handler.dispatchMessage(Handler.java:99)  
     at android.os.Looper.loop(Looper.java:137)  
     at android.app.ActivityThread.main(ActivityThread.java:5041)  
     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:793)  
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)  
     at dalvik.system.NativeStart.main(Native Method)  
    Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml 
     at com.google.maps.api.android.lib6.c.ad.a(Unknown Source) 
     at com.google.maps.api.android.lib6.a.e.a(Unknown Source) 
     at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source) 
     at com.google.android.gms.maps.internal.CreatorImpl.b(Unknown Source) 
     at com.google.android.gms.maps.internal.h.onTransact(SourceFile:62) 
     at android.os.Binder.transact(Binder.java:310) 
     at com.google.android.gms.maps.internal.ah.b(SourceFile:179) 
     at com.google.android.gms.maps.internal.CreatorImpl.b(SourceFile:100) 
     at com.google.android.gms.maps.internal.ag.onTransact(SourceFile:62) 
     at android.os.Binder.transact(Binder.java:310) 
     at com.google.android.gms.maps.internal.zzc$zza$zza.zzs(Unknown Source) 
     at com.google.android.gms.maps.SupportMapFragment$zzb.zzzW(Unknown Source) 
     at com.google.android.gms.maps.SupportMapFragment$zzb.zza(Unknown Source) 
     at com.google.android.gms.dynamic.zza.zza(Unknown Source) 
     at com.google.android.gms.dynamic.zza.onInflate(Unknown Source) 
     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 
     at android.support.v4.app.Fragment.onInflate(Fragment.java:1129) 
     at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2283) 
     at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:111) 
     at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:314) 
     at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31) 
     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79) 
     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680) 
     at android.view.LayoutInflater.inflate(LayoutInflater.java:466)  
     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)  
     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)  
     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)  
     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)  
     at com.example.agupta.routebus.MainActivity.onCreate(MainActivity.java:29)  
     at android.app.Activity.performCreate(Activity.java:5104)  
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)  
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)  
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)  
     at android.app.ActivityThread.access$600(ActivityThread.java:141)  
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)  
     at android.os.Handler.dispatchMessage(Handler.java:99)  
     at android.os.Looper.loop(Looper.java:137)  
     at android.app.ActivityThread.main(ActivityThread.java:5041)  
     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:793)  
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)  
     at dalvik.system.NativeStart.main(Native Method)  
02-06 20:38:48.198 15186-15190/? D/dalvikvm: GC_CONCURRENT freed 280K, 6% free 7594K/8020K, paused 2ms+2ms, total 20ms 
+0

你有沒有看到你的錯誤消息,它說'API密鑰找不到',以及該怎麼辦? –

回答

0

創建映射您沒有API密鑰來訪問谷歌地圖這個錯誤波紋管。首先,您需要從Google開發人員網站獲取API密鑰,並將其保存到您的字符串資源文件中,然後在Manifest文件中指定密鑰。然後只有你可以訪問谷歌地圖。

Caused by: java.lang.RuntimeException: API key not found. Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml 
+0

Aastha

+0

請在此處添加您的源代碼,雖然錯誤表示您沒有密鑰。 –

+1

添加密鑰字符串資源文件包含您的API_KEY –

0

@prashant-gupta的回答也是有效的。但是您可能正在使用較新版本的Android版地圖。如果您查看Getting Started頁面,則步驟4表明您創建了Android Studio創建的google_maps_api.xml。一旦你在開發者控制檯中創建了一個API密鑰,將它複製到xml中,它應該可以正常工作。