2014-03-03 77 views
-1

我正在嘗試製作一個簡單的應用程序,該應用程序此時具有谷歌地圖視圖。目前,我正在使用xml佈局中使用的片段類出現錯誤。錯誤的logcat,.java代碼和XML都包含在內。我一直在下面教程here我也曾嘗試解決方案herehere沒有成功:在佈局xml中膨脹類片段時出錯

*編輯與更新文件

錯誤日誌

03-03 13:10:31.465: E/AndroidRuntime(18671): FATAL EXCEPTION: main 
03-03 13:10:31.465: E/AndroidRuntime(18671): java.lang.RuntimeException: Unable to start activity ComponentInfo{io.github.ukopenlexingtonseniordesign.busalert/io.github.ukopenlexingtonseniordesign.busalert.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.ActivityThread.access$600(ActivityThread.java:127) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.os.Looper.loop(Looper.java:137) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.ActivityThread.main(ActivityThread.java:4507) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at java.lang.reflect.Method.invokeNative(Native Method) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at java.lang.reflect.Method.invoke(Method.java:511) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at dalvik.system.NativeStart.main(Native Method) 
03-03 13:10:31.465: E/AndroidRuntime(18671): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.view.LayoutInflater.inflate(LayoutInflater.java:466) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:280) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Activity.setContentView(Activity.java:1835) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at io.github.ukopenlexingtonseniordesign.busalert.MainActivity.onCreate(MainActivity.java:13) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Activity.performCreate(Activity.java:4465) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932) 
03-03 13:10:31.465: E/AndroidRuntime(18671): ... 11 more 
03-03 13:10:31.465: E/AndroidRuntime(18671): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Fragment.instantiate(Fragment.java:581) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Fragment.instantiate(Fragment.java:549) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Activity.onCreateView(Activity.java:4235) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:673) 
03-03 13:10:31.465: E/AndroidRuntime(18671): ... 20 more 
03-03 13:10:31.465: E/AndroidRuntime(18671): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment 
03-03 13:10:31.465: E/AndroidRuntime(18671): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at java.lang.ClassLoader.loadClass(ClassLoader.java:501) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at java.lang.ClassLoader.loadClass(ClassLoader.java:461) 
03-03 13:10:31.465: E/AndroidRuntime(18671): at android.app.Fragment.instantiate(Fragment.java:571) 
03-03 13:10:31.465: E/AndroidRuntime(18671): ... 23 more 

MainActivity.java:

package io.github.ukopenlexingtonseniordesign.busalert; 

import android.app.Activity; 
import android.os.Bundle; 
import android.support.v4.app.Fragment; 
import android.view.Menu; 

public class MainActivity extends Activity { 

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

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:name="com.google.android.gms.maps.MapFragment"/> 

的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="io.github.ukopenlexingtonseniordesign.busalert" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="12" 
     android:targetSdkVersion="19" /> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 

    <permission 
     android:name="io.github.ukopenlexingtonseniordesign.busalert.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-permission android:name="io.github.ukopenlexingtonseniordesign.busalert.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET"/> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="io.github.ukopenlexingtonseniordesign.busalert.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="AIzaSyCjGTI1myam9dyf6Cay1h379drj98nAjSM"/> 

     <uses-library android:name="com.google.android.maps" /> 

     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="4242000" /> 

    </application> 

</manifest> 

線 「機器人:值=」 4242000 「」 在清單是因爲另一個誤差的quickfix。謝謝您的時間,我希望有人能弄清楚什麼是錯的

回答

2

更改此

android:name="com.google.android.gms.maps.MapFragment"/> 

android:name="com.google.android.gms.maps.SupportMapFragment"/> 

你有

public class MainActivity extends FragmentActivity 

FragmentActivity是基本活動基於支持的片段。我想你想支持地圖片段API級別11和以下,在這種情況下,你需要使用SupportMapFragment

+0

對不起,那不是我的意圖。我曾在另一個問題上看到過這個問題,並試圖看看它是否能解決我的問題。我已經改回到「擴展活動」,並且仍然得到有關膨脹片段的相同錯誤。 – PapaHenry

+0

@ user3373932發佈清單文件和您所做的更改以及新的堆棧跟蹤,根本不需要理解而不嘗試 – Raghunandan

+0

我已經更新了文件並添加了清單。我很抱歉,我在不瞭解其後果的情況下進行了更改。感謝您的時間Raghunandan – PapaHenry

0
android:id="@+id/@android:id/map" 
android:name="com.google.android.gms.maps.SupportMapFragment"/> 
相關問題