当我尝试在我的Android应用程序中添加Google地图时,将运行时异常作为“充气类片段”。我查看了我之前发布的所有类似的评论。但我无法解决它。 日志文件附在此处
08-07 05:30:41.587: E/AndroidRuntime(2574): FATAL EXCEPTION: main
08-07 05:30:41.587: E/AndroidRuntime(2574): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newapp/com.example.newapp.NewApp}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.os.Looper.loop(Looper.java:137)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.reflect.Method.invoke(Method.java:525)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-07 05:30:41.587: E/AndroidRuntime(2574): at dalvik.system.NativeStart.main(Native Method)
08-07 05:30:41.587: E/AndroidRuntime(2574): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.Activity.setContentView(Activity.java:1895)
08-07 05:30:41.587: E/AndroidRuntime(2574): at com.example.newapp.NewApp.onCreate(NewApp.java:12)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.Activity.performCreate(Activity.java:5133)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-07 05:30:41.587: E/AndroidRuntime(2574): ... 11 more
08-07 05:30:41.587: E/AndroidRuntime(2574): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-07 05:30:41.587: E/AndroidRuntime(2574): ... 21 more
08-07 05:30:41.587: E/AndroidRuntime(2574): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.example.newapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.newapp-1, /vendor/lib, /system/lib]]
08-07 05:30:41.587: E/AndroidRuntime(2574): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-07 05:30:41.587: E/AndroidRuntime(2574): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-07 05:30:41.587: E/AndroidRuntime(2574): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
08-07 05:30:41.587: E/AndroidRuntime(2574): ... 24 more
08-07 05:30:47.677: I/Process(2574): Sending signal. PID: 2574 SIG: 9
08-07 05:30:53.767: D/AndroidRuntime(2650): Shutting down VM
08-07 05:30:53.767: W/dalvikvm(2650): threadid=1: thread exiting with uncaught exception (group=0x414c4700)
08-07 05:30:53.857: E/AndroidRuntime(2650): FATAL EXCEPTION: main
08-07 05:30:53.857: E/AndroidRuntime(2650): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.newapp/com.example.newapp.NewApp}: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.access$600(ActivityThread.java:141)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.os.Handler.dispatchMessage(Handler.java:99)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.os.Looper.loop(Looper.java:137)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.reflect.Method.invoke(Method.java:525)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-07 05:30:53.857: E/AndroidRuntime(2650): at dalvik.system.NativeStart.main(Native Method)
08-07 05:30:53.857: E/AndroidRuntime(2650): Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class fragment
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.Activity.setContentView(Activity.java:1895)
08-07 05:30:53.857: E/AndroidRuntime(2650): at com.example.newapp.NewApp.onCreate(NewApp.java:12)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.Activity.performCreate(Activity.java:5133)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
08-07 05:30:53.857: E/AndroidRuntime(2650): ... 11 more
08-07 05:30:53.857: E/AndroidRuntime(2650): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-07 05:30:53.857: E/AndroidRuntime(2650): ... 21 more
08-07 05:30:53.857: E/AndroidRuntime(2650): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.example.newapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.newapp-1, /vendor/lib, /system/lib]]
08-07 05:30:53.857: E/AndroidRuntime(2650): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
08-07 05:30:53.857: E/AndroidRuntime(2650): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
08-07 05:30:53.857: E/AndroidRuntime(2650): at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
08-07 05:30:53.857: E/AndroidRuntime(2650): ... 24 more
08-07 05:30:56.837: I/Process(2650): Sending signal. PID: 2650 SIG: 9
manifest.xml文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="********************************" />
<permission
android:name="com.venky.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newapp.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.newapp.NewApp"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
和java文件NewApp.java
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class NewApp extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_app);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.new_app, menu);
return true;
}
}
activity_new_app.xml
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".NewApp" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
请帮我解决这个问题。
答案 0 :(得分:0)
一个明显的错误
https://developers.google.com/maps/documentation/android/start
您的元标记必须是清单
中应用标记的子代 <meta-data // should be inside application tag.
android:name="com.google.android.maps.v2.API_KEY"
android:value="********************************" />
更改此
<permission
android:name="com.venky.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
到
<permission
android:name="com.example.newapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />